shapely

Polygon intersection error in Shapely: “shapely.geos.TopologicalError: The operation 'GEOSIntersection_r' produced a null geometry”

折月煮酒 提交于 2019-12-07 03:14:46
问题 I have been trying to debug this problem but unable to do so. I am trying to find the intersection of two Polygon objects. It works most of the time but for the following case, it raises the following exception: P1 area: 13.125721955 P2 area: 1.0 Traceback (most recent call last): File "geom2d.py", line 235, in <module> print p1.intersection(p2) File "/usr/local/lib/python2.7/dist-packages/shapely/geometry/base.py", line 334, in intersection return geom_factory(self.impl['intersection'](self,

Find the intersection between two geographical data points

徘徊边缘 提交于 2019-12-06 11:00:42
问题 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 \

Fix up shapely polygon object when discontinuous after map projection

别来无恙 提交于 2019-12-06 09:06:29
问题 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

Geodesic buffering in python

前提是你 提交于 2019-12-06 02:49:41
问题 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? 回答1: 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

Error importing Polygon from shapely.geometry.polygon

寵の児 提交于 2019-12-05 19:33:59
In my Anaconda 2.2 64bit with Python 3.4.3 the following line works well: import shapely But the following line: from shapely.geometry.polygon import Polygon returns the following error: OSError: [WinError 126] The specified module could not be found What am I missing? EDIT I tried with iNotebook, idle.exe and Eclipse. They all use Anaconda (the only Python installation on my computer) and they all show the same error. If I type from shapely.geometry import Polygon in Eclipse, then I click on Polygon , then I press F3 , Eclipse is able to open the module C:\Anaconda3\Lib\site-packages\shapely

Adding a matplotlib colorbar from a PatchCollection

冷暖自知 提交于 2019-12-05 17:11:46
I'm converting a Shapely MultiPolygon to a PatchCollection, and first colouring each Polygon like so: # ldn_mp is a MultiPolygon cm = plt.get_cmap('RdBu') num_colours = len(ldn_mp) fig = plt.figure() ax = fig.add_subplot(111) minx, miny, maxx, maxy = ldn_mp.bounds w, h = maxx - minx, maxy - miny ax.set_xlim(minx - 0.2 * w, maxx + 0.2 * w) ax.set_ylim(miny - 0.2 * h, maxy + 0.2 * h) ax.set_aspect(1) patches = [] for poly in ldn_mp: colour = cm(1. * len(filter(poly.contains, points)) / num_colours) patches.append(PolygonPatch(poly, fc=colour, ec='#555555', lw=0.2, alpha=1., zorder=1)) pc =

Shapely Split LineStrings at Intersections with other LineStrings

和自甴很熟 提交于 2019-12-05 09:52:31
I have a set of LineStrings which are intersected by other LineStrings and I want to split the LineString into separate segments at these intersection points. I have a solution but I don't think it's the best approach. Let's say we are dealing with one LineString: >>> import shapely >>> from shapely.geometry import * >>> import geopandas as gpd >>> >>> MyLine=LineString([(0,0),(5,0),(10,3)]) >>> MyLine <shapely.geometry.linestring.LineString object at 0x1277EEB0> >>> And 2 lines that intersect this LineString: >>> IntersectionLines=gpd.GeoSeries([LineString([(2,1.5),(3,-.5)]), LineString([(5,

Interpolating every X distance along multiline in shapely

送分小仙女□ 提交于 2019-12-05 06:38:05
If I have a shapely multiline object that contains many lines whose total length each is 50km (when traced from the origin), and I want to interpolate along the multiline every X meters (let's say 100m), returning shapely point objects every 100m, how can I achieve this? Here is what I have so far, but it only returns one distinct point (when I know it should return several thousand, as tested in ArcMap): points = [] for x in range(100,50000,100): x,y = multiline.interpolate(x).xy xy = (x[0],y[0]) points.append(xy) trim = list(set(points)) And here is what trim contains: [(-90.5864707030599,

Shapely: Polygon from String?

放肆的年华 提交于 2019-12-05 05:12:15
I have saved string representations of some Shapely Polygons: 'POLYGON ((51.0 3.0, 51.3 3.61, 51.3 3.0, 51.0 3.0))' Is there some fast way of directly converting it back to the Polygon type? Or do I need to manually parse the strings to create Polygon objects? ewcz Shapely can directly parse this : import shapely.wkt P = shapely.wkt.loads('POLYGON ((51.0 3.0, 51.3 3.61, 51.3 3.0, 51.0 3.0))') print(P) 来源: https://stackoverflow.com/questions/51855917/shapely-polygon-from-string

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

风流意气都作罢 提交于 2019-12-05 02:19:09
问题 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