# Tagged Questions

Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects.

4k views

### Python Efficiency — Need suggestions about how to use OGR and Shapely in more efficient way

I'm looking for some suggestions about how to make my python code more efficient. Normally efficiency doesn't matter for me but I am now working with a text file of US locations with over 1.5 million ...
660 views

### Calculating Focal Statistics for Special Neighborhood?

I'm looking to calculate focal statistics for each cell of a raster, within a neighborhood of a specified criteria. Background - I have three binary rasters, each representing a single vegetation ...
3k views

### Polygon overlay with Shapely

I'm trying to capture all the non-overlapping polygons indicated below using Shapely (given polygons A,B & C). Moreover, I'm hoping to do so without iteration, testing for intersect etc. The ...
9k views

### using shapely: translating between Polygons and MultiPolygons

[EDIT: the solution to this was simply to use OGR to read shapefiles. See geographika's example.] In an ESRI shapefile, there is no distinction between Polygons and MultiPolygons. Furthermore, there ...
2k views

### Find Nearest Line Segments to Point

Background From a known Point, I require to establish the nearest surrounding "visible perimeter" against a table of MultiLineStrings, as shown on the diagram. I've searched this site with a number ...
649 views

### How to split two interscting polygons by the average linestring of the shared area (QGIS / python shapely)

I have two polygons, POLYGON((-5 -5,-5 5,5 5,5 -5,-5 -5)) POLYGON((1 1, 1 7, 7 7, 7 1, 1 1)) and wish to split them evenly. The result should be a split along the red marked line. I'm using ...
10k views

### How to write Shapely geometries to shapefiles?

Can someone demonstrate a simple way to write geometry data-structures from shapely into shapefiles? I am particularly interested in polygons with holes and linestrings. It would also be beneficial to ...
191 views

### “Greedy” clipping lines with polygon

I am wishing to clip a set of polylines (black lines in image below) to the outer boundary of a polygon. Any voids within the polygon should be ignored. My ideal output are the dashed yellow lines. ...
3k views

### Converting KML files for use with Python library Shapely

I am trying to get a KML-file (wijken.kml) into Shapely. The KML-file is validated against the proper XML schema, so I guess the input is correct. Routes I have tried: 1) Converting to WKT or WKB ...
128 views

### Polygons across international dateline [-180..+180 longitude]

I'm trying to generate polygons for satellite orbital swaths. So far I have a method to generate two lines which represent the edge of each swath in [lat,long]. Some of the swath's cross the ...
1k views

### Is there a significantly faster way to buffer than arcmap? [duplicate]

I hope this question is appropriate here and I apologize if it is more of a discussion question than a specific technical problem. I have to buffer 150,000 polygons for a real estate project. While ...
2k views

### Dissolve polygons based on attributes with Python (shapely - fiona)

I have been trying to create a function that does basically the same thing that the QGIS "dissolve" function. I thought it would be super easy but well apparently not. So from what I have gathered ...
5k views

### Creating Shapely MultiPolygons from shape file MultiPolygons

I'm reading a shapefile using Fiona: with fiona.open('data/boroughs/boroughs_n.shp') as source: mpolys = [p for p in source] candidate = polys[0]['geometry'] this gives me a dict containing a ...
3k views

### Why is Shapely not installing correctly?

I am trying to run Shapely on a new machine, and tried both installing it from source, using the installer on its webpage, and using pip install shapely. Every reference I try to make from the library ...
2k views

### Python, shapely library: is it possible to do an affine operation on shape polygon?

I am trying to create a rotated rectangle in lat/lon coordinates. Basically, I have the coordinates of the center and rotation angle around the center. Is it possible to do using, shapely or gdal, ...
1k views

### Line vs. Polygon Intersection Coordinates

I am working with Python, Shapely and Fiona... Is there any way where I can give in an input of a line shapefile and a polygon shapefile, and get a result of the intersection points and their ...
652 views

### How do you fix Overlapping Lines?

I have a line dataset that contains some lines where the "end points" are actually found in the middle of the line. In the image below, the nodes are shown in green and one of the end points in red. ...
2k views

### how would one get the end points of a polyline?

I am attempting to write a script to get the end points of a series polylines, and then use those end points to create a polygon. I'm not sure which tools to begin to use on this project. I would ...
1k views

### Transforming Shapely Polygon and MultiPolygon objects

Is there an easy way of transforming Shapely objects (namely, Polygons and MultiPolygons) from one projection to another without having to dig around and extract coordinates by hand? In fact, I don'...
1k views

### Python: How to export Shapely objects to DXF file

Using shapely package for Python how to export the resulting shapely objects such as buffer to a DXF file?
5k views

### GEOS and Shapely installation on Windows

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 ...
327 views

### intersecting two shapefiles from Python or command line

I'm new to working with geo data and trying to address a similar question to the one posted here. Using command line and/or shapely/fiona, in the most efficient and elegant way. I created two ...
1k views

### Understanding the Use of Spatial Indexes

I'm having trouble understanding the use of spatial indexes with RTree. Example: I have 300 buffered points, and I need to know each buffer's intersection area with a polygon shapefile. The polygon ...
1k views

### Wrap GEOS functionality into python

I've been looking on how to get GEOSExtractLine available in python. I looked into Shapely source to if it was available for it, but it's not. I'm trying to wrap this funcionality into Django, much ...
888 views

### How to computational efficiently check if there are any overlapping polygons in a group of polygons?

I need to do some processing with groups of polygons. If any of the polygons in the group overlaps other polygon the result is unpredictable and don't throw any error. So, I need to detect if there is ...
157 views

### Counting features into intersections of Shapely Polygons

I have a geopandas GeoDataFrame containing hundreds of shapely Polygon and MultiPolygon geometries. The polygons overlap in lots of places. I'd like to make a new geometry that contains a count of how ...
3k views

### Intersect Shapefiles using Shapely

What I'd like to try and do is intersect some point buffers with census tracts, maintain their ID's and the tracts attributes. I found a sample from http://www.macwright.org/2012/10/31/gis-with-...
2k views

### What is the unit the shapely length attribute?

I'm doing a very simple calculation of the length of a polyline using shapely: from shapely.geometry import LineString ... xy_list = [map(float,e) for e in xy_intm] line = LineString(xy_list) s = '%...
655 views

### Install Shapely with GEOS on heroku

I have a web mapping app running on Heroku. My app is written in python. Using pip I was able to install various pure python libraries that were needed. I would now like to install Shapely too. ...
5k views

### Shapely unable to tell if polygon contains point

For an application I want to determine under which constituency a given coordinate falls. After looking at the various options, I decided upon shapely and fiona as the easiest way to implement this. ...
1k views

### Find distance and heading from a point to a polygon in lat, lon coordinates

I have counties mapped using polygons in Shapely with latitude/longitude for coordinates. Given a complex polygon x and single point y, how would I find the shortest distance between x and y as well ...
950 views

### Reading postgis geometry with shapely

I am doing a small-scale workflow in ipython notebook with geopandas and shapely, pulling a bunch of geospatial data, sometimes from shapefiles, sometimes from postgis (where more expensive processing ...
410 views

### geopandas/shapely: what units it uses/calculates for area and distance functions?

it looks like a silly question, yet I can't find clear answer on that: what units geopandas/shapely use calculating distance/area between objects?
354 views

### Is there an online reference available for the Fiona and Shapely libraries?

Is there an online reference available for the Fiona and Shapely libraries? I'm thinking a real reference, beside the tutorial-style documentation: http://toblerity.github.io/shapely/manual.html ...
2k views

### How to install shapely for python 2.6 (Mac) NOT 2.7?

I'm trying to use Polygonizer plugin inside QGIS, but it needs Shapely to work. I've installed Shapely (pip install Shapely) but that's for python 2.7. QGIS works with python 2.6 (on Snow Leopard) and ...
435 views

### How to generate overlapping polygons from lines output from Table To Ellipse tool?

I have a feature class of line-based ellipses generated by the Table to Ellipse tool that looks like this: What I want is polygons of the individual ellipses, however tools like Feature to Polygon ...
595 views

### How to deal with direction (CW, CCW) of circles, in particular with shapely?

I am translating an input that describes zones by mixing segments and arcs. Arcs are given by a center, 2 points (beginning/end of arc) and a direction (CW or CCW). In a first prototypes using GDAL, I ...
28 views

### “Merging” 2 layers of LineString with splits at intersections

I would like to "merge" 2 networks of lines and these lines need to be split when they intersect. With pictures it should be clearer : What to do: if a black line intersects a red line, they ...
607 views

### Area in KM from Polygon of coordinates

I have polygons from coordinates in (python shapely) that looks like this POLYGON ((24.8085317 46.8512821, 24.7986952 46.8574619, 24.8088238 46.8664741, 24.8155239 46.8576335, 24.8085317 46.8512821)) ...
2k views

### Converting Matplotlib contour objects to Shapely objects

I would like to convert a Matplotlib contour collection to a Shapely geometry collection, in order to calculate the area contained within closed contour lines. it seems that all the information is ...
451 views

### Can I convert the sharp edges of a polygon easily to round edges?

I use the python module "shapely" to make Polygons (like below). Can I convert the sharp edges of a polygon easily to round edges? Such that when I have unified some polygons I could issue a command ...
167 views

### Can this Be Recoded to Be More Efficient with Respect to Processing Time?

I'm very new to GIS but have been asked to parse through any given ESRI GDB file-folder without using any ESRI product. I've been trying to focus on using Fiona and Shapely as these seem to be ...
571 views

### Removing small polygons gaps in a Shapely polygon

I know this issue has been addressed before with different software, but I am looking for an approach with Shapely. I have a polygon with a very small gap on the interior of the shape: Here is a ...
3k views

### How to install shapely on Ubuntu 12.10

I have tried to install shapely on Ubuntu 12.10. Therefore I installed libgeos-c1, pip and shapely with \$ pip install Shapely. The shapely files are now in /home/user/build/Shapely. When I try to ...
492 views

### Shapely/ Python looping through a number of polygons

I am trying to loop through a set of polygons in shapely so using python) to determine whether they overlap or not. I do not want to do it manually as later i want to generalise the procedure and do ...
5k views

### Determine if point is within an irregular polygon using Python

I would like to create a mask of a grid where points are evaluated as either 1's or 0's depending on if they lay outside of an irregular (i.e. not rectangular) polygon. I have a set of high-latitude ...
90 views

### When validating geometries, what are “Nested shells”?

I am validating shapefiles polygon geometry using shapely, and have also attempted it using FME. Some polygons return the error "Nested Shells". I cannot find a definition of what the problem is, ...
156 views

### What is Shapely library alternative in R?

I want to manipulate 2D geospatial geometries in R. I am used to using Shapely in Python but I am a newbie in R. Can you suggest Shapely alternatives for R?
2k views

### How to create a Shapely LineString from two Points

If have two points, from which I want to create a straight LineString object: from shapely.geometry import Point, LineString A = Point(0,0) B = Point(1,1) The Shapely manual for LineString states: ...
843 views

### create polygon adjacency matrix using python

I am trying to create an adjacency matrix from a set of polygons. That is, I have a bunch of polygons and I want to identify which polygons have a common edge or "touch" each other. Once I find this ...