Exemplo n.º 1
0
func featureToInfraSpace(feature *geojson.Feature) *InfraSpace {
	point, _ := feature.GetGeometry()
	coordinate := point.(*geojson.Point).Coordinates
	prop := feature.Properties
	return &InfraSpace{
		Point_: appengine.GeoPoint{
			Lng: float64(coordinate[0]),
			Lat: float64(coordinate[1]),
		},
		Value_: int(prop[spaceValueName].(float64)),
	}
}
Exemplo n.º 2
0
// DecodeLineStringFromFeatureJSON decode geojson feature type lineString into *LineString
func DecodeLineStringFromFeatureJSON(gj []byte) (*LineString, error) {
	var f *geojson.Feature
	json.Unmarshal(gj, &f)
	g, err := f.GetGeometry()
	if err != nil {
		return nil, err
	}
	ls, _ := g.(*geojson.LineString)
	points := []*Point{}
	for _, c := range ls.Coordinates {
		points = append(points, DecodePoint(c))
	}
	return NewLineString(points), nil
}
Exemplo n.º 3
0
// 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
}
Exemplo n.º 4
0
// 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 *Feature, err error) {
	// TODO: This sucks... I just want to switch on Coordinates.(type)
	igeom, err := gj.GetGeometry()
	if igeom == nil || err != nil {
		err = util.Errorf("Invalid geojson feature %q", gj)
		return
	}
	feature = NewFeature(igeom.GetType())
	//TODO filter properties
	feature.Properties = gj.Properties
	if feature.Properties != nil {
		feature.Properties["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:
		feature = nil

		err = util.Errorf("Invalid Coordinate Type in GeoJson %q", geom)
	}
	return
}