def test_center_feature(): f1 = Feature(geometry=Point((-97.522259, 35.4691))) f2 = Feature(geometry=Point((-97.502754, 35.463455))) f3 = Feature(geometry=Point((-97.508269, 35.463245))) feature_collection = FeatureCollection([f1, f2, f3]) feature = center(feature_collection) assert feature["geometry"]["coordinates"] == [-97.512507, 35.466172]
def define_origin(geojson, origin): if not origin: origin = "centroid" if isinstance(origin, list): return get_coord(origin) bb = bbox(geojson) west = bb[0] south = bb[1] east = bb[2] north = bb[3] if (origin == "sw" or origin == "southwest" or origin == "westsouth" or origin == "bottomleft"): return [west, south] elif (origin == "se" or origin == "southeast" or origin == "eastsouth" or origin == "bottomright"): return [east, south] elif (origin == "nw" or origin == "northwest" or origin == "westnorth" or origin == "topleft"): return [west, north] elif (origin == "ne" or origin == "northeast" or origin == "eastnorth" or origin == "topright"): return [east, north] elif origin == "center": return center(geojson)["geometry"]["coordinates"] elif origin is None or origin == "centroid": return centroid(geojson)["geometry"]["coordinates"] else: raise Exception("invalid origin")