From 2ba36d1d811b67a9314eddf1f8181ed924c3afd4 Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 17 Jan 2012 18:17:56 -0500 Subject: [PATCH] make simplification configurable, still default to 0.0001 --- .../management/commands/loadshapefiles.py | 15 ++++++++++----- .../management/commands/startshapedefinitions.py | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/boundaryservice/management/commands/loadshapefiles.py b/boundaryservice/management/commands/loadshapefiles.py index 912bf45..564017b 100644 --- a/boundaryservice/management/commands/loadshapefiles.py +++ b/boundaryservice/management/commands/loadshapefiles.py @@ -135,6 +135,13 @@ def add_boundaries_for_layer(self, config, layer, set, database): else: layer_srs = layer.srs + # Simplification can be configured but default is to create simplified + # geometry field by collapsing points within 1/1000th of a degree. + # For reference, Chicago is at approx. 42 degrees latitude this works + # out to a margin of roughly 80 meters latitude and 112 meters + # longitude for Chicago area. + simplification = config.get('simplification', 0.0001) + # Create a convertor to turn the source data into transformer = CoordTransform(layer_srs, db_srs) @@ -143,12 +150,10 @@ def add_boundaries_for_layer(self, config, layer, set, database): geometry = self.polygon_to_multipolygon(feature.geom) geometry.transform(transformer) - # Create simplified geometry field by collapsing points within 1/1000th of a degree. - # Since Chicago is at approx. 42 degrees latitude this works out to an margin of - # roughly 80 meters latitude and 112 meters longitude. # Preserve topology prevents a shape from ever crossing over itself. - simple_geometry = geometry.geos.simplify(0.0001, preserve_topology=True) - + simple_geometry = geometry.geos.simplify(simplification, + preserve_topology=True) + # Conversion may force multipolygons back to being polygons simple_geometry = self.polygon_to_multipolygon(simple_geometry.ogr) diff --git a/boundaryservice/management/commands/startshapedefinitions.py b/boundaryservice/management/commands/startshapedefinitions.py index 2954d54..dcfd7e7 100644 --- a/boundaryservice/management/commands/startshapedefinitions.py +++ b/boundaryservice/management/commands/startshapedefinitions.py @@ -77,7 +77,11 @@ def handle(self, *args, **options): 'encoding': '', # SRID of the geometry data in the shapefile if it can not be inferred from an accompanying .prj file # This is normally not necessary and can be left undefined or set to an empty string to maintain the default behavior - 'srid': '' + 'srid': '', + # Simplification tolerance to use when creating the simple_geometry + # column for this shapefile, larger numbers create polygons with fewer + # points. + 'simplification': 0.0001, } } """