Calculating distance between point and MultiPolygon Geoseries object in PythonPython Shapely - filling small...

What options are left, if Britain cannot decide?

How do anti-virus programs start at Windows boot?

An Accountant Seeks the Help of a Mathematician

How is the Swiss post e-voting system supposed to work, and how was it wrong?

Why did it take so long to abandon sail after steamships were demonstrated?

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Do I need life insurance if I can cover my own funeral costs?

Dot in front of file

What does it mean to make a bootable LiveUSB?

What is this large pipe coming out of my roof?

Is it true that real estate prices mainly go up?

Why must traveling waves have the same amplitude to form a standing wave?

Latest web browser compatible with Windows 98

Be in awe of my brilliance!

Define, (actually define) the "stability" and "energy" of a compound

What are some nice/clever ways to introduce the tonic's dominant seventh chord?

Have researchers managed to "reverse time"? If so, what does that mean for physics?

Running a subshell from the middle of the current command

How to write cleanly even if my character uses expletive language?

Make a transparent 448*448 image

Welcoming 2019 Pi day: How to draw the letter π?

Calculus II Professor will not accept my correct integral evaluation that uses a different method, should I bring this up further?

Is it possible that AIC = BIC?

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver



Calculating distance between point and MultiPolygon Geoseries object in Python


Python Shapely - filling small gaps between multi polygonsCalculating distance between linestring and polygon with geopandasHow to get a Multipolygon object from Overpass QL?Unexpected intersects behavior between GeoSeries of Polygons and one of PointsGet distance between point and nearest polygonAlgorithm for Calculating Distance Between Two PointsCalculating distance between a Point and a MultiPolygon PostGIS objectPerform sjoin in geopandas leads to:'AttributeError: 'GeoSeries' object has no attribute 'columns''Getting error while importing GeoPandas in Python consoleHow to fix 'GeoSeries' object has no attribute '_geom'













1















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


Result



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










share|improve this question









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.

























    1















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


    Result



    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










    share|improve this question









    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.























      1












      1








      1








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


      Result



      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










      share|improve this question









      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.












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


      Result



      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







      python polygon distance shapely geopandas






      share|improve this question









      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.











      share|improve this question









      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.









      share|improve this question




      share|improve this question








      edited 50 secs ago









      Taras

      2,2342727




      2,2342727






      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.









      asked 3 hours ago









      ansmalansmal

      61




      61




      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.





      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.






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






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






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










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315594%2fcalculating-distance-between-point-and-multipolygon-geoseries-object-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








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










          draft saved

          draft discarded


















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













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












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
















          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315594%2fcalculating-distance-between-point-and-multipolygon-geoseries-object-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...