Questions tagged [shapely]

PostGIS-ish operations outside a database context for Pythoneers and Pythonistas.

Shapely is a BSD-licensed Python package (see Shapely · PyPI) 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. This C dependency is traded for the ability to execute with blazing speed. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are. For more details, see the Shapely manual.

1113 questions
8
votes
1 answer

Is it bad practice to have more than 1 geometry column in a GeoDataFrame?

I'm trying to create a GeoDataFrame with 2 zip codes per row, whose distances from each other I want to compare. I took a list of approx 220 zip codes and ran an itertools combination on them to get all combo's, then unpacked the tuples into two…
var.ela
  • 93
  • 1
  • 5
8
votes
2 answers

Dissolve Overlapping Polygons (with GDAL/OGR) while keeping non-connected results distinct

Is there any way to dissolve (merge) overlapping polygons, using any GDAL/OGR API or command line tool, while keeping the resulting non overlapping areas distinct? I have searched a lot and I cannot find anything resembling what need. However, I…
StarSheriff
  • 1,477
  • 2
  • 17
  • 23
8
votes
4 answers

Shapely Split LineStrings at Intersections with other LineStrings

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…
AJG519
  • 3,249
  • 10
  • 36
  • 62
8
votes
1 answer

Identify unique groupings of polygons in Geopandas / Shapely

Let's say I have two disjoint groups / "islands" of polygons (think census tracts in two non-adjacent counties). My data could look something like this: >>> p1=Polygon([(0,0),(10,0),(10,10),(0,10)]) >>>…
AJG519
  • 3,249
  • 10
  • 36
  • 62
8
votes
3 answers

How to group intersecting Shapely geometric objects in a list of tuples

I have one list of data as follows: from shapely.geometry import box data = [box(1,2,3,4), box(5,6,7,8), box(1,2,3,4)] codes = ['A','B','C'] The list 'data' has following elements: A = box(1,2,3,4) B = box(5,6,7,8) C = box(1,2,3,4) I have to…
Roman
  • 3,007
  • 8
  • 26
  • 54
8
votes
1 answer

Add new points to existing Polygon in Shapely

How do I modify an existing Polygon? For a start, I'd like to add a Point to its exterior. poly = Polygon([(0, 0), (1, 1), (1, 0)]) I was looking for something like this: poly.append_at(idx=3, Point(1, -1)) But I cannot find any even similar methods…
racic
  • 1,235
  • 11
  • 20
7
votes
3 answers

Efficiently match point to geometry (point in poly) for large collections of both points and polygons

There are a lot of questions here about matching points in polygons efficiently (examples: Here and Here). The primary variables of interest in these are high number of points N, and number of polygon vertices V. These are all good and useful, but…
amquack
  • 837
  • 10
  • 24
7
votes
4 answers

using qgis and shaply error: GEOSGeom_createLinearRing_r returned a NULL pointer

I tried to create a polygon shapefile in QGIS and read it in python by shapely. An example code looks like this: import fiona from shapely.geometry import shape multipolys = fiona.open(somepath) multi = multipolys[0] coord =…
jjk
  • 71
  • 1
  • 3
7
votes
0 answers

How to find the points of hausdorff_distance() in Shapely?

The Shapely hausdorff_distance() function returns a single (scalar) value. Is there a way to get the/a pair of points on both geometries that fit this distance? Similar to how we have nearest_points() relative to distance().
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
7
votes
2 answers

How to plot a list of Shapely points

I created a list of Shapely Point objects based on the point data set. How can I plot this list of points below? points = [Point(-4.85624511894443, 37.1837967179202), Point(-4.855703975302475, 37.18401757756585), …
Hello-experts
  • 113
  • 1
  • 1
  • 10
7
votes
1 answer

how to determine if a point is inside a polygon using geojson and shapely

I am hoping to create a region on a map and be able to automatically determine if points (coordinates) are inside that region. I'm using a geojson file of the entire US and coordinates for New York City for this example. Geojson:…
Josh
  • 239
  • 3
  • 6
7
votes
2 answers

Point in polygon using shapely?

I am running the following script which I believe should be returning TRUE for the point being in the polygon but it is returning FALSE. from shapely import geometry polygon = [(-1571236.8349707182, 8989180.222117377), (1599362.9654156454,…
user2512696
  • 315
  • 2
  • 6
  • 13
7
votes
2 answers

How to create polygons with arcs in shapely (or a better library)

I am trying to use shapely to identify the area used by a shape and the area used by the tools that will cut it on a CNC router. The shape is imported from a dxf drawing using ezdxf. The tool paths can be either rectangles (if they are cut by a saw…
stenci
  • 8,290
  • 14
  • 64
  • 104
6
votes
1 answer

Why do I get an error when trying to read a file in geopanda's included datasets?

I've just installed Anaconda in my new laptop, and created an environment with geopandas installed in it. I've tried to upload the world map that comes with geopandas through the following code: import geopandas as gpd world =…
Fernando
  • 63
  • 1
  • 5
6
votes
2 answers

how to find the nearest LINESTRING to a POINT?

How do I fund the nearest LINESTRING near a point? First I have a list of LINESTRING and point value. How do I have the nearest LINESTRING to the POINT (5.41 3.9) and maybee the distance? from shapely.geometry import Point, LineString line_string =…
helpme
  • 163
  • 3
  • 9