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

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'][0],req_data['geometry'][1]]
boundary = gpd.GeoSeries(cascaded_union(polygons))
boundary.plot(color = 'black')


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

New contributor
ansmal is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

ansmal is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.