1

I am using Python in a Jupyter notebook.

I'have created a geometry with shapely and I need to extract the coordinate of the north-west corner of it.

from shapely.geometry import Polygon

lng = -180
lat=-90
lon_point_list = [lng, lng+10, lng+10, lng]
lat_point_list = [lat, lat, lat+10, lat+10]
    
polygon_geom = Polygon(zip(lon_point_list, lat_point_list))

of course this shape is an example but my shape is always a rectangle

Is there a trick to perform it ? (I can use another library such as geopandas)

0

The following approach uses geopandas bounds to extract the minx, miny, maxx, maxy value of the rectangle bounds. From there, simply extract the minx and maxy values to produce the northwest corner coordinate. Note that this approach assumes the rectangle is not rotated.

from shapely.geometry import Polygon
import geopandas as gpd

lng = -180
lat=-90
lon_point_list = [lng, lng+10, lng+10, lng]
lat_point_list = [lat, lat, lat+10, lat+10]
    
polygon_geom = Polygon(zip(lon_point_list, lat_point_list))

# Returns a tuple with minx, miny, maxx, maxy of bounding box
b = polygon_geom.bounds

# Find the NW corner of bounds (minx, maxy)
nw_corner = (b[0], b[3])
print(nw_corner)
| improve this answer | |
  • To be less general, my use case is to retrieve tiles from a dataset (world have been cut in small pieces of 10x10°) so not a single is rotated. This solution is perfect for me ! – Pierrick Rambaud Jul 16 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.