Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simplify boundary geometries in shapely

I'm working with shapely to do GIS, but I'm running into memory errors when loading the geometry of each zip code into memory because the geometry is so jagged and complicated.

I'd like to make the shape smaller in memory by reducing the number of boundary points as low as possible without distorting the shape too much. Using the convex hull seems like one potential answer, as could simply throwing away lots of points from the boundary. I'm wondering if there's something already out there that solves this problem.

like image 613
Michael K Avatar asked Apr 03 '14 14:04

Michael K


People also ask

What is wkt shapely?

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.

What is LineString in Python?

A LineString has zero area and non-zero length. >>> from shapely.geometry import LineString >>> line = LineString([(0, 0), (1, 1)]) >>> line. area 0.0 >>> line. length 1.4142135623730951. Its x-y bounding box is a (minx, miny, maxx, maxy) tuple.

What is Unary_union?

unary_union. Returns a geometry containing the union of all geometries in the GeoSeries .


1 Answers

Try using the geometry's simplify method, specifying a tolerance distance.

like image 185
Mike T Avatar answered Sep 19 '22 16:09

Mike T