[polygons] Addindg ability to specify include properties by filename
This commit is contained in:
@@ -55,17 +55,23 @@ class RTreePolygonIndex(object):
|
|||||||
preserve_topology = self.preserve_topology
|
preserve_topology = self.preserve_topology
|
||||||
return poly.simplify(simplify_tolerance, preserve_topology=preserve_topology)
|
return poly.simplify(simplify_tolerance, preserve_topology=preserve_topology)
|
||||||
|
|
||||||
def add_polygon(self, poly, properties):
|
def add_polygon(self, poly, properties, include_only_properties=None):
|
||||||
if self.include_only_properties:
|
if include_only_properties is not None:
|
||||||
properties = {k: v for k, v in properties.iteritems() if k in self.include_only_properties}
|
properties = {k: v for k, v in properties.iteritems() if k in include_only_properties}
|
||||||
self.polygons.append((properties, prep(poly)))
|
self.polygons.append((properties, prep(poly)))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_shapefiles(cls, inputs, output_dir,
|
def create_from_shapefiles(cls, inputs, output_dir,
|
||||||
index_filename=DEFAULT_INDEX_FILENAME,
|
index_filename=DEFAULT_INDEX_FILENAME,
|
||||||
polys_filename=DEFAULT_POLYS_FILENAME):
|
polys_filename=DEFAULT_POLYS_FILENAME,
|
||||||
|
include_only_properties=None):
|
||||||
index = cls(save_dir=output_dir, index_filename=index_filename)
|
index = cls(save_dir=output_dir, index_filename=index_filename)
|
||||||
for input_file in inputs:
|
for input_file in inputs:
|
||||||
|
if include_only_properties is not None:
|
||||||
|
include_props = include_only_properties.get(input_file, cls.include_only_properties)
|
||||||
|
else:
|
||||||
|
include_props = cls.include_only_properties
|
||||||
|
|
||||||
f = fiona.open(input_file)
|
f = fiona.open(input_file)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
@@ -85,7 +91,7 @@ class RTreePolygonIndex(object):
|
|||||||
polys.append(poly)
|
polys.append(poly)
|
||||||
index.index_polygon(i, poly)
|
index.index_polygon(i, poly)
|
||||||
|
|
||||||
index.add_polygon(MultiPolygon(polys), rec['properties'])
|
index.add_polygon(MultiPolygon(polys), rec['properties'], include_only_properties=include_props)
|
||||||
i += 1
|
i += 1
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user