func readGeoJson(path string) (features *geojson.FeatureCollection) { file, err := ioutil.ReadFile(path) if err != nil { util.Check(err) } if err := json.Unmarshal(file, &features); err != nil { util.Check(err) } return features }
func (g *Geometry) toVtGeometry() (vtgeom []uint32) { cmds := make(chan *command, 100) go func() { defer close(cmds) for _, shape := range g.shapes { for _, cmd := range shape.ToCommands() { cmds <- cmd } } }() chunks := make(chan []*command, 100) go func() { defer close(chunks) chunk := []*command{} for cur := range cmds { if len(chunk) == 0 || chunk[0].cid == cur.cid { chunk = append(chunk, cur) } else { chunks <- chunk chunk = []*command{cur} } } chunks <- chunk }() for chunk := range chunks { geom, err := flushCommands(chunk) util.Check(err) vtgeom = append(vtgeom, geom...) } return }
func rtreegoRect(s *Shape) *rtreego.Rect { bbox := s.BoundingBox() p := rtreego.Point{bbox.min.X(), bbox.min.Y()} d := bbox.max.Difference(bbox.min) rect, err := rtreego.NewRect(p, [2]float64{d.X(), d.Y()}) util.Check(err) return &rect }
func geometryFromVt(vt_type vt.Tile_GeomType, vtgeom []uint32) *Geometry { shapes, gtype, err := vtShapes(vtgeom) util.Check(err) if vt_type != gtype { util.Info("Assigned GeomType did not match sniffed %v -> %v", vt_type, gtype) } return newGeometry(vt_type, shapes...) }
func (s *Shape) BoundingBox() Box { h := s.Head() min, max := h, h for _, c := range s.Coordinates { if c.Lat < min.Lat { min.Lat = c.Lat } if c.Lat > max.Lat { max.Lat = c.Lat } if c.Lon < min.Lon { min.Lon = c.Lon } if c.Lon > max.Lon { max.Lon = c.Lon } } box, err := NewBox(min, max) util.Check(err) return box }
desc := c.String("desc") layer := c.String("layer-name") zmin := c.Int("min") zmax := c.Int("max") extent := c.Int("extent") upsert := c.Bool("upsert") force := c.Bool("force") // validate if len(c.Args()) == 0 || out == "" { util.Die(c, "input_source & --out required") } else if zmax < zmin || zmin < 0 || zmax > 23 { util.Die(c, "--max > --min, --min > 0 --max < 24 not satisfied") } // execute source, err := getSource(c) util.Check(err) if force { os.Remove(out) } tiles, err := InitTiles(out, upsert, desc, extent) util.Check(err) err = tiles.Build(source, layer, zmin, zmax) util.Check(err) // finalize file, _ := os.Open(out) defer file.Close() stat, _ := file.Stat() exp := float64(stat.Size()) / float64(1<<20) util.Info("%s was successfully caught!", out) util.Info("Diglet gained %f MB of EXP!", exp) },
// Flatten all the points of a feature into single list. This can hel in identifying which tiles are going to be // created func geojsonFeatureAdapter(gj *geojson.Feature) (feature *geo.Feature) { // TODO: This sucks... I just want to switch on Coordinates.(type) igeom, err := gj.GetGeometry() util.Check(err) feature = geo.NewFeature(igeom.GetType()) //TODO filter properties feature.Properties = gj.Properties feature.ID = gj.Id //TODO if id == nil assign a fake one feature.Type = igeom.GetType() switch geom := igeom.(type) { case *geojson.Point: shape := coordinatesAdapter(geojson.Coordinates{geom.Coordinates}) feature.AddShape(shape) case *geojson.LineString: shape := coordinatesAdapter(geom.Coordinates) feature.AddShape(shape) case *geojson.MultiPoint: shape := coordinatesAdapter(geom.Coordinates) feature.AddShape(shape) case *geojson.MultiLineString: for _, line := range geom.Coordinates { shape := coordinatesAdapter(line) feature.AddShape(shape) } case *geojson.Polygon: // mvt need exterior ring to be clockwise // and interior rings to counter-clockwise exterior := true for _, line := range geom.Coordinates { shape := coordinatesAdapter(line) if exterior { if !shape.IsClockwise() { shape.Reverse() } exterior = false } else { if shape.IsClockwise() { shape.Reverse() } } feature.AddShape(shape) } case *geojson.MultiPolygon: for _, multiline := range geom.Coordinates { exterior := true for _, line := range multiline { shape := coordinatesAdapter(line) if exterior { if !shape.IsClockwise() { shape.Reverse() } exterior = false } else { if shape.IsClockwise() { shape.Reverse() } } feature.AddShape(shape) } } default: panic("Invalid Coordinate Type in GeoJson Feature") // + feature.String()) } return }