shapely

How to create a Polygon given its Point vertices?

陌路散爱 提交于 2019-11-28 02:37:56
问题 I want to create a polygon from shapely points. from shapely import geometry p1 = geometry.Point(0,0) p2 = geometry.Point(1,0) p3 = geometry.Point(1,1) p4 = geometry.Point(0,1) pointList = [p1, p2, p3, p4, p1] poly = geometry.Polygon(pointList) gives me an type error TypeError: object of type 'Point' has no len() How to create a Polygon from shapely Point objects? 回答1: If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a

Install Shapely: OSError: [WinError 126] The specified module could not be found

断了今生、忘了曾经 提交于 2019-11-27 23:29:44
问题 I have to install Shapely package (http://toblerity.org/shapely/project.html#installation). But when I am using: pip install Shapely I am getting this error: Collecting Shapely Using cached Shapely-1.5.17.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\AppData\Local\Temp\pip-build-mwuxcain\Shapely\setup.py", line 38, in <module> from shapely._buildcfg import geos_version_string, geos_version,

Could not find library geos_c or load any of its variants

末鹿安然 提交于 2019-11-27 20:21:46
I use python in fedora 19. I wanted to run the following line Python: import shapely.geometry the following error appears: OSError: Could not find or load any library geos_c icts of variants ['libgeos_c.so.1', 'libgeos_c.so'] I installed the package Shapely, and the following two libraries: glibc-2.17-4.fc19.i686.rpm geos-3.3.8-2.fc19.i686.rpm I just looked for the solution of this problem on the web, but I have not found Please, help me ! PaF Installed shapely using pip, and had the same problem. So I went ahead and installed it like so: sudo apt-get install libgeos-dev And it worked. I'm

Coordinates of the closest points of two geometries in Shapely

落花浮王杯 提交于 2019-11-27 20:06:01
There is a polyline with a list of coordinates of the vertices = [(x1,y1), (x2,y2), (x3,y3),...] and a point(x,y). In Shapely, geometry1.distance(geometry2) returns the shortest distance between the two geometries. >>> from shapely.geometry import LineString, Point >>> line = LineString([(0, 0), (5, 7), (12, 6)]) # geometry2 >>> list(line.coords) [(0.0, 0.0), (5.0, 7.0), (12.0, 6.0)] >>> p = Point(4,8) # geometry1 >>> list(p.coords) [(4.0, 8.0)] >>> p.distance(line) 1.4142135623730951 But I also need to find the coordinate of the point on the line that is closest to the point(x,y). In the

Faster way of polygon intersection with shapely

眉间皱痕 提交于 2019-11-27 06:48:38
I have a large number of polygons (~100000) and try to find a smart way of calculating their intersecting area with a regular grid cells. Currently, I am creating the polygons and the grid cells using shapely (based on their corner coordinates). Then, using a simple for-loop I go through each polygon and compare it to nearby grid cells. Just a small example to illustrate the polygons/grid cells. from shapely.geometry import box, Polygon # Example polygon xy = [[130.21001, 27.200001], [129.52, 27.34], [129.45, 27.1], [130.13, 26.950001]] polygon_shape = Polygon(xy) # Example grid cell gridcell

Calculate overlapped area between two rectangles

十年热恋 提交于 2019-11-27 05:23:19
问题 I want to calculate the overlapped area "THE GRAY REGION" between red and blue rectangles. Each rectangle is defined by its four corner coordinates. The resulted unit of the overlapped area is unit square. I could not imagine how can I do it? Any creative comments would be appreciated. 回答1: This type of intersection is easily done by the "min of the maxes" and "max of the mins" idea. To write it out one needs a specific notion for the rectangle, and, just to make things clear I'll use a

Looking for a fast way to find the polygon a point belongs to using Shapely

我与影子孤独终老i 提交于 2019-11-27 03:41:11
问题 I have a set of ~36,000 polygons which represent a partition (~counties) of the country. My python script receives a lot of points: pointId, longitude, latitude. For each point, I want to send back pointId, polygonId. For each point, looping into all the polygons and use myPoint.within(myPolygon) is quite inefficient. I suppose the shapely library offers a better way to prepare the polygon so that finding the polygon for a point becomes a tree path (country, region, sub region, ...) Here is

Coordinates of the closest points of two geometries in Shapely

限于喜欢 提交于 2019-11-26 22:50:24
问题 There is a polyline with a list of coordinates of the vertices = [(x1,y1), (x2,y2), (x3,y3),...] and a point(x,y). In Shapely, geometry1.distance(geometry2) returns the shortest distance between the two geometries. >>> from shapely.geometry import LineString, Point >>> line = LineString([(0, 0), (5, 7), (12, 6)]) # geometry2 >>> list(line.coords) [(0.0, 0.0), (5.0, 7.0), (12.0, 6.0)] >>> p = Point(4,8) # geometry1 >>> list(p.coords) [(4.0, 8.0)] >>> p.distance(line) 1.4142135623730951 But I

Could not find library geos_c or load any of its variants

元气小坏坏 提交于 2019-11-26 19:55:35
问题 I use python in fedora 19. I wanted to run the following line Python: import shapely.geometry the following error appears: OSError: Could not find or load any library geos_c icts of variants ['libgeos_c.so.1', 'libgeos_c.so'] I installed the package Shapely, and the following two libraries: glibc-2.17-4.fc19.i686.rpm geos-3.3.8-2.fc19.i686.rpm I just looked for the solution of this problem on the web, but I have not found Please, help me ! 回答1: Installed shapely using pip, and had the same

Faster way of polygon intersection with shapely

丶灬走出姿态 提交于 2019-11-26 10:28:05
问题 I have a large number of polygons (~100000) and try to find a smart way of calculating their intersecting area with a regular grid cells. Currently, I am creating the polygons and the grid cells using shapely (based on their corner coordinates). Then, using a simple for-loop I go through each polygon and compare it to nearby grid cells. Just a small example to illustrate the polygons/grid cells. from shapely.geometry import box, Polygon # Example polygon xy = [[130.21001, 27.200001], [129.52,