[fix] include properties
This commit is contained in:
@@ -83,7 +83,7 @@ class RTreePolygonIndex(object):
|
|||||||
if poly_type == 'Polygon':
|
if poly_type == 'Polygon':
|
||||||
poly = Polygon(rec['geometry']['coordinates'][0])
|
poly = Polygon(rec['geometry']['coordinates'][0])
|
||||||
index.index_polygon(i, poly)
|
index.index_polygon(i, poly)
|
||||||
index.add_polygon(poly, rec['properties'])
|
index.add_polygon(poly, rec['properties'], include_only_properties=include_props)
|
||||||
elif poly_type == 'MultiPolygon':
|
elif poly_type == 'MultiPolygon':
|
||||||
polys = []
|
polys = []
|
||||||
for coords in rec['geometry']['coordinates']:
|
for coords in rec['geometry']['coordinates']:
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ class ReverseGeocoder(RTreePolygonIndex):
|
|||||||
input_files,
|
input_files,
|
||||||
output_dir,
|
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):
|
||||||
|
|
||||||
init_languages()
|
init_languages()
|
||||||
index = cls(save_dir=output_dir, index_filename=index_filename)
|
index = cls(save_dir=output_dir, index_filename=index_filename)
|
||||||
@@ -109,6 +110,11 @@ class ReverseGeocoder(RTreePolygonIndex):
|
|||||||
for input_file in input_files:
|
for input_file in input_files:
|
||||||
f = fiona.open(input_file)
|
f = fiona.open(input_file)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
filename = os.path.split(input_file)[-1]
|
filename = os.path.split(input_file)[-1]
|
||||||
|
|
||||||
for rec in f:
|
for rec in f:
|
||||||
@@ -121,7 +127,7 @@ class ReverseGeocoder(RTreePolygonIndex):
|
|||||||
poly = Polygon(rec['geometry']['coordinates'][0])
|
poly = Polygon(rec['geometry']['coordinates'][0])
|
||||||
index.index_polygon(i, poly)
|
index.index_polygon(i, poly)
|
||||||
poly = index.simplify_polygon(poly)
|
poly = index.simplify_polygon(poly)
|
||||||
index.add_polygon(poly, dict(rec['properties']))
|
index.add_polygon(poly, dict(rec['properties']), include_only_properties=include_props)
|
||||||
elif poly_type == 'MultiPolygon':
|
elif poly_type == 'MultiPolygon':
|
||||||
polys = []
|
polys = []
|
||||||
for coords in rec['geometry']['coordinates']:
|
for coords in rec['geometry']['coordinates']:
|
||||||
@@ -130,7 +136,7 @@ class ReverseGeocoder(RTreePolygonIndex):
|
|||||||
index.index_polygon(i, poly)
|
index.index_polygon(i, poly)
|
||||||
|
|
||||||
multi_poly = index.simplify_polygon(MultiPolygon(polys))
|
multi_poly = index.simplify_polygon(MultiPolygon(polys))
|
||||||
index.add_polygon(multi_poly, dict(rec['properties']))
|
index.add_polygon(multi_poly, dict(rec['properties']), include_only_properties=include_props)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user