Georg Heiler
Georg Heiler

Reputation: 17676

gis calculate distance between point and polygon / border

I want to calculate the distance between a point and the border of a country using python / shapely. It should work just fine point.distance(poly) e.g. demonstrated here Find Coordinate of Closest Point on Polygon Shapely but using geopandas I face the issue of: 'GeoSeries' object has no attribute '_geom'

What is wrong in my handling of the data? My border dataset is from http://www.gadm.org/

'GeoSeries' object has no attribute '_geom'

Upvotes: 5

Views: 7648

Answers (1)

eguaio
eguaio

Reputation: 3954

According to geopandas documentation, a GeoSeries is a vector of geometries (in your case, 0 (POLYGON... tells that you have just one object, but it is still a vector). There should be a way of getting the first geometry element. GeoSeries class implements the __getitem__ method, so austriaBorders.geometry[0] should give you the geometry you need. So, try with point.distance(austriaBorders.geometry[0]).

If you only need the distance to a point, the GeoSeries has the distance method implemented, but it will return a vector with the distance to each geometry it contains (according to documentation).

Upvotes: 6

Related Questions