You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, using Extent.from_ons_code() returns the extents as WGS84 without an option to choose the projection. Using these extents as input to FeaturesAPI and saving the data as a geojson means that the X and Y coordinates are flipped, because geojson requires longitude before latitude, whereas WGS84 outputs latitude before longitude. Now, I've solved this using the following code and perhaps you may want to incorporate something similar in your code?
import geopandas as gpd
from osdatahub import FeaturesAPI, Extent
import geojson
from shapely import geometry
from shapely.ops import transform
from pathlib import Path
import pyproj
def switch_lat_lon(polygon):
"""Reproject Extent.polygon as EPSG:27700."""
project = pyproj.Transformer.from_proj(pyproj.Proj(init='epsg:4326'), pyproj.Proj(init='epsg:27700')) # reprojection from EPSG:4326 to EPSG:27700
output_poly = transform(project.transform, polygon) # apply projection
return output_poly
# running the reprojection:
ward_cd = "E05000437"
ward_nm = "Bellingham"
save_path = Path('./Data/wards/')
if not save_path.is_dir():
save_path.mkdir()
extent = Extent.from_ons_code(ward_cd)
poly = switch_lat_lon(extent.polygon)
ward_extent_as_27700 = Extent(poly, 'EPSG:27700')
product = "zoomstack_local_buildings"
features = FeaturesAPI(key, product, ward_extent_as_27700)
results = features.query(limit=50)
file_save_path = save_path.joinpath(f"{ward_nm}.geojson")
geojson.dump(results, open(file_save_path.as_posix(), "w"))
Now, the one issue this code has is that it throws a FutureWarning:
FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
I'm currently ignoring this warning because changing the syntax breaks the function. You may be able to find a better solution.
The text was updated successfully, but these errors were encountered:
Currently, using Extent.from_ons_code() returns the extents as WGS84 without an option to choose the projection. Using these extents as input to FeaturesAPI and saving the data as a geojson means that the X and Y coordinates are flipped, because geojson requires longitude before latitude, whereas WGS84 outputs latitude before longitude. Now, I've solved this using the following code and perhaps you may want to incorporate something similar in your code?
Now, the one issue this code has is that it throws a
FutureWarning
:I'm currently ignoring this warning because changing the syntax breaks the function. You may be able to find a better solution.
The text was updated successfully, but these errors were encountered: