Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How select cities from country (geopandas)?

I would like to select cities from polygon (Poland), but filter points in polygon doesn’t work.
I have code:

import geopandas
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world=world[world.name == 'Poland']
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
world['geometry']
cities['geometry']
c=world['geometry'].contains(cities['geometry'])
cities[c.values]

Unfortunately the results are only "False". Could You help me ? Why "contains" is not working ?
Is another way to select cities in geopandas ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Doing read_file() with mask argument or an sjoin() should be the same. Currently due to an issues with compatibility of geos and gdal versions these are not the same on my environment.

import geopandas

world = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
world = world[world.name == "Poland"]
cities = geopandas.read_file(geopandas.datasets.get_path("naturalearth_cities"))
cities = geopandas.read_file(
    geopandas.datasets.get_path("naturalearth_cities"), mask=world
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading