shapely

How to deal with rounding errors in Shapely

限于喜欢 提交于 2019-11-29 18:31:03
问题 I have a case which is based on projecting a point on a line and then separate this line on it. My use case is slightly more complicated, but my problem can be reproduced with the following code: from shapely import * line1 = LineString([(1,1.2), (2,2), (3, 2.), (4,1.2)]) pt = Point(2.5, 1.2) pr = line1.interpolate(line1.project(pt)) By construction, "pr" should be on line1 and their intersection too: line1.contains(pr) line1.intersects(LineString([pt, pr])) prints two times "True". But

Ubuntu中安装shapely

五迷三道 提交于 2019-11-29 17:23:42
直接使用pip install shapely 安装 shapely后,当import时会发生错误 from shapely.geometry import Point, LineString, Polygon OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so 发现是缺少geos的库,但是在geos官网下载了源码编译安装后,错误依旧。后来在在geos官网上发现这玩意有现成的二进制包,通过apt-get install libgeos-dev安装后问题解决 来源: oschina 链接: https://my.oschina.net/u/140833/blog/411213

Shapely地理空间几何对象库的安装与使用

大兔子大兔子 提交于 2019-11-29 17:23:28
Shapely 1.5.13 Downloads ↓ Geometric objects, predicates, and operations Manipulation and analysis of geometric objects in the Cartesian plane. Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is based on the widely deployed GEOS (the engine of PostGIS ) and JTS (from which GEOS is ported) libraries. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are. For more details, see: Shapely on GitHub The Shapely manual Requirements Shapely 1.5.x requires Python >=2.6 (including

How to create a Polygon given its Point vertices?

隐身守侯 提交于 2019-11-29 13:09:46
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? If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a list comprehension. In other words: from shapely import geometry poly = geometry.Polygon([[p.x, p.y] for p in

Determine if Shapely point is within a LineString/MultiLineString

谁说我不能喝 提交于 2019-11-29 11:02:49
I am trying to use Shapely's within function to do a 'spatial join' of a LineString and a Point file (FYI, the point file was generated using the interpolate function on the LineString ). Problem is - nothing is being returned. # this condition is never satisfied if point.within(line): # here I write stuff to a file where: point = POINT (-9763788.9782693591000000 5488878.3678984242000000) line = LINESTRING (-9765787.998118492 5488940.974948905, -9748582.801636808 5488402.127570709) What am I missing? There are floating point precision errors when finding a point on a line. Use the distance

OSError geos_c could not be found when Installing Shapely

冷暖自知 提交于 2019-11-29 09:13:14
I'm a newbie to making/plotting on maps with python, been trying to follow this blogpost to generate a world map (http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-data-on-a-world-map-with-python/). Got stuck with a few things here: Installing Basemap (a Matplotlib extension for plotting data on geographic projections). from mpl_toolkits.basemap import Basemap Traceback (most recent call last): File "geos_demo.py", line 1, in <module> from mpl_toolkits.basemap import Basemap ImportError: No module named mpl_toolkits.basemap Install Shapely, but the following error occurs [1]:

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

限于喜欢 提交于 2019-11-29 02:11:55
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, polygonize import shapely.geometry as geometry from scipy.spatial import Delaunay import numpy as np

Find coordinate of the closest point on polygon in Shapely

倖福魔咒の 提交于 2019-11-28 23:19:34
Say I have the following Polygon and Point: >>> poly = Polygon([(0, 0), (2, 8), (14, 10), (6, 1)]) >>> point = Point(12, 4) I can calculate the point's distance to the polygon... >>> dist = point.distance(poly) >>> print(dist) 2.49136439561 ...but I would like to know the coordinate of the point on the polygon border where that shortest distance measures to. My initial approach is to buffer the point by its distance to the polygon, and find the point at which that circle is tangent to the polygon: >>> buff = point.buffer(dist) However, I'm not sure how to calculate that point. The two polygon

Calculate overlapped area between two rectangles

北战南征 提交于 2019-11-28 17:57:59
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. 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 namedtuple: from collections import namedtuple Rectangle = namedtuple('Rectangle', 'xmin ymin xmax ymax') ra =

OSError geos_c could not be found when Installing Shapely

こ雲淡風輕ζ 提交于 2019-11-28 02:37:59
问题 I'm a newbie to making/plotting on maps with python, been trying to follow this blogpost to generate a world map (http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-data-on-a-world-map-with-python/). Got stuck with a few things here: Installing Basemap (a Matplotlib extension for plotting data on geographic projections). from mpl_toolkits.basemap import Basemap Traceback (most recent call last): File "geos_demo.py", line 1, in <module> from mpl_toolkits.basemap import Basemap