I want to calculate the distance of a point from the Multiploygon geoseries object created using
cascaded_union function of GeoPandas. Following is my code:
import numpy as np import pandas as pd import geopandas as gpd from shapely.ops import cascaded_union from matplotlib import pyplot as plt from shapely.geometry import LineString, Point, MultiPoint fp = "\\TM_WORLD_BORDERS-0.3\\TM_WORLD_BORDERS-0.3.shp" data = gpd.read_file(fp) mycountries = ['Canada','Russia'] req_data = data[data.NAME.isin(mycountries)] req_data = req_data.reset_index() req_data = req_data.drop('index',axis=1) polygons = [req_data['geometry'],req_data['geometry']] boundary = gpd.GeoSeries(cascaded_union(polygons)) boundary.plot(color = 'black') plt.show()
I require that when I calculate the distance of two points (as shown on the map: red dots) from the MultiPolygon, it should consider Canada for the one in the left side and Russia for the right one. Also, the distance in miles/km.
I tried using distance function but the result which I am getting is not correct. Moreover, if I consider point somewhere in the Indian Ocean, it gives a result as
0 which is again not what I require.
Shapefile can be downloaded from the TM_WORLD_BORDERS-0.3.zip file available at http://thematicmapping.org/downloads/world_borders.php