Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility between Extent.from_ons_code() and FeaturesAPI #63

Open
Ilkka-LBL opened this issue Feb 1, 2023 · 0 comments
Open

Incompatibility between Extent.from_ons_code() and FeaturesAPI #63

Ilkka-LBL opened this issue Feb 1, 2023 · 0 comments

Comments

@Ilkka-LBL
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant