shapely

How to check if a polygon is empty in Shapely?

烂漫一生 提交于 2019-12-05 02:11:48
I'm pretty new to Python so the answer to this question is probably quite simple, but I've looked everywhere and tried a lot but couldn't find the answer. Simplifying a polygon using Shapely may result in an empty polygon. I want to replace the polygon with a point if the polygon is empty. Something that would work like: if mypoly is empty: mypoly = [(0,0)] Given that mypoly is a shapely polygon, you can check if it's empty using is_empty which is built in to Shapely to check for empty ones. from shapely.geometry import Point if mypoly.is_empty: mypoly = Point(0, 0) 来源: https://stackoverflow

Find the intersection between two geographical data points

让人想犯罪 __ 提交于 2019-12-04 18:44:46
I have two pairs of lat/lon (expressed in decimal degrees) along with their radius (expressed in meters). What I am trying to achieve is to find if an intersect between these two points exits (of course, it is obvious that this doesn't hold here but the plan is to try this algorithm in many other data points). In order to check this I am using Shapely's intersects() function. My question however is how should I deal with the different units? Should I make some sort of transformation \ projection first (same units for both lat\lon and radius)? 48.180759,11.518950,19.0 47.180759,10.518950,10.0

Fix up shapely polygon object when discontinuous after map projection

一笑奈何 提交于 2019-12-04 14:16:19
This demo program (intended to be run in an IPython notebook; you need matplotlib , mpl_toolkits.basemap , pyproj , and shapely ) is supposed to plot increasingly large circles on the surface of the Earth. It works correctly as long as the circle does not cross over one of the poles. If that happens, the result is complete nonsense when plotted on a map (see below cell 2) If I plot them "in a void" instead of on a map (see below cell 3) the results are correct in the sense that, if you removed the horizontal line going from +180 to -180 longitude, the rest of the curve would indeed delimit the

Geodesic buffering in python

China☆狼群 提交于 2019-12-04 08:29:09
Given land polygons as a Shapely MultiPolygon , I want to find the (Multi-)Polygon that represents the e.g. 12 nautical mile buffer around the coastlines. Using the Shapely buffer method does not work since it uses euclidean calculations. Can somebody tell me how to calculate geodesic buffers in python? This is not a shapely problem, since shapely explicitly tells in its documentation that the library is for planar computation only. Nevertheless, in order to answer your question, you should specify the coordinate systems you are using for your multipolygons. Assuming you are using WGS84

centos libgeos repository missing

百般思念 提交于 2019-12-04 03:31:24
问题 On centos 7.3 minimal trying to install shapely or geopandas requires access to https://github.com/libgeos/libgeos libgeos. Trying to install this via sudo yum install libgeos-dev tells me that this package is not available. It seems that I am lacking a repository. So far I have been unable to find a working one as http://trac.osgeo.org/geos is pointing to https://yum.postgresql.org/repopackages.php#pg96 for the RPM but still after rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.6

Polygon containment test in matplotlib artist

我们两清 提交于 2019-12-03 21:43:33
I have the following code, gathered initially from here. , which uses matplotlib, shapely, cartopy to draw a world map. When a click is made, I need to determine on which country it was made. I am able to add a pick_event callback to the canvas, however, it is called on every artist.(cartopy.mpl.feature_artist.FeatureArtist, which corresponds to a country). Given an artist and a mouse event with x, y coordinates, how can I determine containment? I've tried artist.get_clip_box().contains , but it is not really a polygon, rather a plain rectangle. The default containment test for the

Find closest line to each point on big dataset, possibly using shapely and rtree

☆樱花仙子☆ 提交于 2019-12-03 16:59:34
I have a simplified map of a city that has streets in it as linestrings and addresses as points. I need to find closest path from each point to any street line. I have a working script that does this, but it runs in polynomial time as it has nested for loop. For 150 000 lines (shapely LineString) and 10 000 points (shapely Point), it takes 10 hours to finish on 8 GB Ram computer. The function looks like this (sorry for not making it entirely reproducible): import pandas as pd import shapely from shapely import Point, LineString def connect_nodes_to_closest_edges(edges_df , nodes_df, edges_geom

Calculate Distance to Nearest Feature with Geopandas

偶尔善良 提交于 2019-12-03 13:29:01
问题 I'm looking to do the equivalent of the ArcPy Generate Near Table using Geopandas / Shapely. I'm very new to Geopandas and Shapely and have developed a methodology that works, but I'm wondering if there is a more efficient way of doing it. I have two point file datasets - Census Block Centroids and restaurants. I'm looking to find, for each Census Block centroid, the distance to it's closest restaurant. There are no restrictions in terms of same restaurant being the closest restaurant for

shapely and matplotlib point-in-polygon not accurate with geolocation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 13:00:11
问题 I am testing the point-in-polygon function with matplotlib and shapely. Here is a map contains a Bermuda triangle polygon. Google maps 's point-in-polygon functions clearly shows testingPoint and testingPoint2 are inside of the polygon which is a correct result. if I test the two points in matplotlib and shapely, only point2 passes the test. In [1]: from matplotlib.path import Path In [2]: p = Path([[25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737]]) In [3]: p1=[27

Calculate Distance to Nearest Feature with Geopandas

纵饮孤独 提交于 2019-12-03 06:33:16
I'm looking to do the equivalent of the ArcPy Generate Near Table using Geopandas / Shapely. I'm very new to Geopandas and Shapely and have developed a methodology that works, but I'm wondering if there is a more efficient way of doing it. I have two point file datasets - Census Block Centroids and restaurants. I'm looking to find, for each Census Block centroid, the distance to it's closest restaurant. There are no restrictions in terms of same restaurant being the closest restaurant for multiple blocks. The reason this becomes a bit more complicated for me is because the Geopandas Distance