[osm/polygons] Storing polygon JSON under a different key so it doesn't have to be read from disk after a successful cache matched point-in-polygon test just to retrieve the properties
This commit is contained in:
@@ -99,7 +99,6 @@ class PolygonIndex(object):
|
|||||||
return {
|
return {
|
||||||
'type': 'Feature',
|
'type': 'Feature',
|
||||||
'geometry': mapping(poly),
|
'geometry': mapping(poly),
|
||||||
'properties': properties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def add_polygon(self, poly, properties, cache=False, include_only_properties=None):
|
def add_polygon(self, poly, properties, cache=False, include_only_properties=None):
|
||||||
@@ -109,12 +108,10 @@ class PolygonIndex(object):
|
|||||||
if not self.persistent_polygons or cache:
|
if not self.persistent_polygons or cache:
|
||||||
self.polygons[self.i] = prep(poly)
|
self.polygons[self.i] = prep(poly)
|
||||||
|
|
||||||
if not self.persistent_polygons:
|
if self.persistent_polygons:
|
||||||
value = json.dumps(properties)
|
self.polygons_db.Put(self.polygon_key(self.i), json.dumps(self.polygon_geojson(poly, properties)))
|
||||||
else:
|
|
||||||
value = json.dumps(self.polygon_geojson(poly, properties))
|
|
||||||
|
|
||||||
self.polygons_db.Put(str(self.i), value)
|
self.polygons_db.Put(self.properties_key(self.i), json.dumps(properties))
|
||||||
self.index_polygon_properties(properties)
|
self.index_polygon_properties(properties)
|
||||||
self.i += 1
|
self.i += 1
|
||||||
|
|
||||||
@@ -288,13 +285,19 @@ class PolygonIndex(object):
|
|||||||
poly = self.polygons[i]
|
poly = self.polygons[i]
|
||||||
contains = poly.contains(point)
|
contains = poly.contains(point)
|
||||||
if contains:
|
if contains:
|
||||||
properties = json.loads(self.polygons_db.Get(str(i)))
|
properties = json.loads(self.polygons_db.Get(self.properties_key(i)))
|
||||||
if not return_all:
|
if not return_all:
|
||||||
return properties
|
return properties
|
||||||
else:
|
else:
|
||||||
containing.append(properties)
|
containing.append(properties)
|
||||||
return containing
|
return containing
|
||||||
|
|
||||||
|
def polygon_key(self, i):
|
||||||
|
return 'poly:{}'.format(i)
|
||||||
|
|
||||||
|
def properties_key(self, i):
|
||||||
|
return 'props:{}'.format(i)
|
||||||
|
|
||||||
def polygons_contain_cached(self, candidates, point, return_all=False):
|
def polygons_contain_cached(self, candidates, point, return_all=False):
|
||||||
containing = None
|
containing = None
|
||||||
if return_all:
|
if return_all:
|
||||||
@@ -304,7 +307,7 @@ class PolygonIndex(object):
|
|||||||
poly = self.polygons.get(i, None)
|
poly = self.polygons.get(i, None)
|
||||||
data = {}
|
data = {}
|
||||||
if poly is None:
|
if poly is None:
|
||||||
data = json.loads(self.polygons_db.Get(str(i)))
|
data = json.loads(self.polygons_db.Get(self.polygon_key(i)))
|
||||||
poly = prep(self.polygon_from_geojson(data))
|
poly = prep(self.polygon_from_geojson(data))
|
||||||
self.polygons[i] = poly
|
self.polygons[i] = poly
|
||||||
self.cache_misses += 1
|
self.cache_misses += 1
|
||||||
@@ -314,7 +317,7 @@ class PolygonIndex(object):
|
|||||||
contains = poly.contains(point)
|
contains = poly.contains(point)
|
||||||
if contains:
|
if contains:
|
||||||
if not data:
|
if not data:
|
||||||
data = json.loads(self.polygons_db.Get(str(i)))
|
data = json.loads(self.polygons_db.Get(self.properties_key(i)))
|
||||||
|
|
||||||
properties = data['properties']
|
properties = data['properties']
|
||||||
if not return_all:
|
if not return_all:
|
||||||
|
|||||||
Reference in New Issue
Block a user