def test_geometry_collection_iteration(coordinates): """test if feature collection is iterable""" print(coordinates, type(coordinates)) polygon = Point(coordinates=coordinates) feature = Feature(geometry=polygon) gc = FeatureCollection(features=[feature, feature]) iter(gc)
def test_point_valid_coordinates(coordinates): """ Two or three number elements as coordinates shold be okay """ p = Point(coordinates=coordinates) assert p.type == "Point" assert p.coordinates == coordinates assert hasattr(p, "__geo_interface__")
def area_setup(self) -> Dict[str, Any]: response = { "near": { "name": "near", "coverage_area": MultiPolygon( coordinates=[ [ [ (-44.04982, -19.87743), (-44.04982, -19.89438), (-44.04758, -19.89438), (-44.04758, -19.87743), (-44.04982, -19.87743), ] ] ], type="MultiPolygon", ), "address": Point( coordinates=(-44.04925346374511, -19.89383034031159), type="Point", ), }, "farther": { "name": "farther", "coverage_area": MultiPolygon( coordinates=[ [ [ (-44.051098, -19.893265), (-44.038825, -19.8932653), (-44.0388250, -19.890480), (-44.051098, -19.890480), (-44.051098, -19.893265), ] ] ], type="MultiPolygon", ), "address": Point( coordinates=(-44.039876461029046, -19.891509947530643), type="Point", ), }, } return response
def stations_to_geojson(stations: List[Station]) -> FacilityGeo: features = [] for station in stations: if not station.location: continue if not station.facilities or len(station.facilities) < 1: continue feature_dict: Dict = dict(properties=dict()) feature_dict["properties"] = { "station_id": station.id, "station_code": station.code, "facility_id": station.code, "network": station.facilities[0].network.label, "network_country": station.facilities[0].network.country, "state": station.location.state, "postcode": station.location.postcode, "name": station.name, "capacity_registered": station.capacity_registered, # "capacity_aggregate": station.capacity_aggregate, "duid_data": [], } for facility in station.facilities: if not facility.fueltech: continue feature_dict["properties"]["duid_data"].append( { # "oid": facility.oid, # "duid": facility.duid, "fuel_tech": facility.fueltech.code, "fuel_tech_label": facility.fueltech.label, "fuel_tech_renewable": facility.fueltech.renewable, "commissioned_date": facility.registered, "decommissioned_date": facility.deregistered, "status": facility.status.code, "status_label": facility.status.label, "unit_id": facility.unit_id, "unit_number": facility.unit_number, "unit_size": facility.unit_capacity, "unit_alias": facility.unit_alias, # capacities for the unit "capacity_registered": facility.capacity_registered, # "capacity_aggregate": facility.capacity_aggregate, # network specific fields (DUID is one) "network_region": facility.network_region, } ) feature = FacilityFeature(**feature_dict) if station.location and station.location.geom: geom = Point( coordinates=(station.location.lng, station.location.lat) ) if not feature.geometry: feature.geometry = geom features.append(feature) crs = { "type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}, } geo = FacilityGeo(features=features, crs=crs, name="opennem.facilities") return geo
def test_parse_geometry_obj_point(): assert parse_geometry_obj({"type": "Point", "coordinates": [102.0, 0.5]}) == Point( coordinates=(102.0, 0.5) )
def test_point_invalid_coordinates(coordinates): """ Too few or to many elements should not, nor weird data types """ with pytest.raises(ValidationError): Point(coordinates=coordinates)
def test_point(): coordinates = (1, 2) p = Point(coordinates=coordinates) assert p.type == "Point" assert p.coordinates == coordinates assert hasattr(p, "__geo_interface__")
def test_bad_point(): with pytest.raises(ValidationError): Point(coordinates=(1, ))