shapely

Cannot import Shapely (Ubuntu, Python)

拜拜、爱过 提交于 2019-12-24 08:39:37
问题 I downloaded Shapely to do some polygon work (on a Ubuntu AWS instance). Everything installed just fine, I used wget. I also did pip when I first encountered the error I'm about to explain, but it just said everything was there, so I don't think the download is the issue. Anyway, when I try to import anything from shapely, I get this error: OSError: libgeos_c.so: cannot open shared object file: No such file or directory When I just say "import shapely", it all goes fine. However, when I need

count how often each field point is inside a contour

爷,独闯天下 提交于 2019-12-23 16:02:01
问题 I'm working with 2D geographical data. I have a long list of contour paths. Now I want to determine for every point in my domain inside how many contours it resides (i.e. I want to compute the spatial frequency distribution of the features represented by the contours). To illustrate what I want to do, here's a first very naive implementation: import numpy as np from shapely.geometry import Polygon, Point def comp_frequency(paths,lonlat): """ - paths: list of contour paths, made up of (lon,lat

Adding a matplotlib colorbar from a PatchCollection

北城以北 提交于 2019-12-22 09:14:30
问题 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

How to extract interior polygon coordinates using Shapely?

↘锁芯ラ 提交于 2019-12-21 21:42:47
问题 I am new to Shapely (but enthusiastic about it), and recently I've discovered a bit of a road bump. I have a polygon shapefile that I am reading in via Fiona. This shapefile contains BOTH polygon and multipolygon items and I need to build an array for each feature of all the coordinates within it (i.e. both exterior and/or interior). Notably, two of the polygon items have interior rings (and they are valid). I seem to have no problem accessing the exterior coordinates of the polygon(s)

Shapely: Polygon from String?

最后都变了- 提交于 2019-12-21 04:00:24
问题 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? 回答1: 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

Draw an ellipse using Shapely

假装没事ソ 提交于 2019-12-21 03:37:11
问题 I'm integrating Shapely into my code, and I have to deal with several different kinds of geometric objects. Most of my needs are satisfied with Lines, Polygons and LineStrings, but I need to use ellipses. Is there a way to create an ellipse in Shapely by a bounding box or by semi axis, without having to discretize the ellipse into lines? 回答1: There isn't any way to represent a polygon in Shapely without discretizing it. At the base level Shapely deals with points. Everything from a LineString

Get the vertices on a LineString either side of a Point

拟墨画扇 提交于 2019-12-19 10:26:13
问题 I have a shapely LineString and have defined a shapely Point which lies along the LineString . How can I find the vertices of the LineString which lie either side of the point? (split the line in two) 回答1: Locate the line segment in the LineString where the point lies. Then split in two groups the vertices of the LineString accordingly. To locate the line segment, simply apply a point / line segment intersection test to each segment. from shapely.geometry import Point,LineString def split

Estimating an area of an image generated by a set of points (Alpha shapes??)

余生颓废 提交于 2019-12-18 12:38:14
问题 I have a set of points in an example ASCII file showing a 2D image. I would like to estimate the total area that these points are filling. There are some places inside this plane that are not filled by any point because these regions have been masked out. What I guess might be practical for estimating the area would be applying a concave hull or alpha shapes . I tried this approach to find an appropriate alpha value, and consequently estimate the area. from shapely.ops import cascaded_union,

Fix invalid polygon in Shapely

删除回忆录丶 提交于 2019-12-18 11:42:10
问题 Shapely defines a Polygon as invalid if any of its segments intersect, including segments that are colinear. Many software packages will create a region or area with a "cutout" as shown here which has colinear segments: >>> pp = Polygon([(0,0), (0,3), (3,3), (3,0), (2,0), (2,2), (1,2), (1,1), (2,1), (2,0), (0,0)]) >>> pp.is_valid WARNING:shapely.geos:Self-intersection at or near point 2 0 False Naturally, the cutout can be implemented natively in Shapely, or this same geometry can be

Python, GEOS and Shapely on Windows 64

混江龙づ霸主 提交于 2019-12-17 19:32:52
问题 When trying to install Shapely on my Windows 64bit computer, I cannot get the GEOS library to work. So far, I have run the OSGeo4W installer from which I installed GDAL (I believe the geos library is included in that package). After that, I checked and I have geos_c.dll on my C:\OSGeo4W\bin directory, but either I have missed some configuration steps or the library does not work. I need Shapely to work, so I also ran pip install shapely after installing GDAL, and it apparently worked