1

I have two dataframes containing linestrings and polygons.

Example:

LINESTRING (7470683.872444116 5535684.148437066, 7469929.808435988 5533461.643992055, 7469962.299334303 5532960.522156481)

POLYGON ((7470480.135291019 5535154.495749012, 7470503.630338011 5535150.050740123, 7470523.315377379 5535150.050740123, 7470548.715428181 5535147.510735041, 7470569.670470092 5535145.605731232, 7470589.355509464 5535136.080712179, 7470627.455585664 5535129.730699481, 7470646.65736445 5535127.152853454, 7470632.250166068 5535055.919058787, 7470624.22647908 5535060.319664435, 7470610.679785319 5535050.582978293, 7470597.556425741 5535039.999623794, 7470583.586397797 5535039.152955431, 7470543.792984879 5535045.502968134, 7470533.475397702 5535047.81553565, 7470522.045374842 5535045.275530567, 7470508.075346902 5535047.81553565, 7470499.185329122 5535050.990541998, 7470483.31029737 5535060.515561052, 7470473.78527832 5535066.230572477, 7470460.45025165 5535070.040580099, 7470448.385227518 5535084.64560931, 7470438.225207198 5535111.95066392, 7470435.685202118 5535133.540707104, 7470443.940218629 5535146.875733772, 7470452.830236409 5535155.765751552, 7470459.18024911 5535161.480762983, 7470480.135291019 5535154.495749012))

Is there any method I could use to calculate the minimal distance between a 'road' (in dataframe containing linestrings) and polygon? I'm trying geopandas since I have some experience with pandas.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
  • Welcome to GIS SE! Take a look at the tour for new users to see how to structure your question. Adding a code snippet of what you've tried and where you're stuck or what didn't work would be helpful here. – GISHuman Mar 09 '17 at 21:06

2 Answers2

0

There are overlay in your geometry. Every time that I calculate distance from each other, I receive no distance. Result always zero. By the way, I consider that both have the same coordinate reference system. If they have an another, you should inform us.

I think that it would have distance higher than zero only if they don't overlay.

Plot of geometries

Here the script:

import geopandas as gpd
from shapely.wkt import loads

line_wkt = 'LINESTRING (7470683.872444116 5535684.148437066, 7469929.808435988 5533461.643992055, 7469962.299334303 5532960.522156481)'

poly_wkt = 'POLYGON ((7470480.135291019 5535154.495749012, 7470503.630338011 5535150.050740123, 7470523.315377379 5535150.050740123, 7470548.715428181 5535147.510735041, 7470569.670470092 5535145.605731232, 7470589.355509464 5535136.080712179, 7470627.455585664 5535129.730699481, 7470646.65736445 5535127.152853454, 7470632.250166068 5535055.919058787, 7470624.22647908 5535060.319664435, 7470610.679785319 5535050.582978293, 7470597.556425741 5535039.999623794, 7470583.586397797 5535039.152955431, 7470543.792984879 5535045.502968134, 7470533.475397702 5535047.81553565, 7470522.045374842 5535045.275530567, 7470508.075346902 5535047.81553565, 7470499.185329122 5535050.990541998, 7470483.31029737 5535060.515561052, 7470473.78527832 5535066.230572477, 7470460.45025165 5535070.040580099, 7470448.385227518 5535084.64560931, 7470438.225207198 5535111.95066392, 7470435.685202118 5535133.540707104, 7470443.940218629 5535146.875733772, 7470452.830236409 5535155.765751552, 7470459.18024911 5535161.480762983, 7470480.135291019 5535154.495749012))'

line = loads(line_wkt)
g_line = gpd.GeoSeries(line)

poly = loads(poly_wkt)
g_poly = gpd.GeoSeries(poly)

g_poly.plot(ax=g_line.plot(alpha=1), alpha=1)

g_line.distance(g_poly)  
Diogo Caribé
  • 1,960
  • 1
  • 23
  • 37
-1

I'm not familiar with geopandas, but just searching the documentation, I found the following:

distance(other): returns Series with minimum distance from each entry to other

Also, this link explains that,

Any of the attributes calls or methods described for a GeoSeries will work on a GeoDataFrame – effectively, they are just applied to the “geometry” GeoSeries.

Further, this similar post might help.

Fezter
  • 21,867
  • 11
  • 68
  • 123