Skip to content

Commit

Permalink
make simplification configurable, still default to 0.0001
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturk committed Jan 17, 2012
1 parent 67e79d4 commit 2ba36d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions boundaryservice/management/commands/loadshapefiles.py
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion boundaryservice/management/commands/startshapedefinitions.py
Expand Up @@ -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,
}
}
"""

0 comments on commit 2ba36d1

Please sign in to comment.