예제 #1
0
func SymmetricDifference(js geojson.GeoJSON) (*geojson.FeatureCollection, error) {
	polygons, err := geometryToPolygonList(js)
	if err != nil {
		return nil, err
	}
	var features []geojson.Feature
	for i := 0; i < len(polygons); i++ {
		a := polygons[i]
		for j := 0; j < len(polygons); j++ {
			if i == j {
				continue
			}
			var c s2.Polygon
			b := polygons[j]
			c.InitToDifference(a, b)
			a = &c
		}
		if a.NumLoops() > 0 {
			feat := geojson.Feature{
				Typ:      "Feature",
				Geometry: s2PolygonToGeometry(*a),
			}
			features = append(features, feat)
		}
	}
	fc := &geojson.FeatureCollection{
		Typ:      "FeatureCollection",
		Features: features,
	}
	return fc, nil
}
예제 #2
0
func Difference(js geojson.GeoJSON) (*geojson.FeatureCollection, error) {
	polygons, err := geometryToPolygonList(js)
	if err != nil {
		return nil, err
	}
	a := polygons[0]
	for i := 1; i < len(polygons); i++ {
		var c s2.Polygon
		b := polygons[i]
		c.InitToDifference(a, b)
		a = &c
	}
	return featureCollectionFromS2Polygon(a), nil
}