Cropping box to stop excessive creation of clusters

parent c25ad266
......@@ -17,7 +17,6 @@ import string
from vec2d import vec2d
from textures.manager import find_matching_texture
import os
from shapely.geometry.point import Point
import re
import ac3d_fast
# nobjects = 0
......@@ -227,7 +226,7 @@ def is_static_object_nearby(b, X, static_tree):
if parameters.OVERLAP_CHECK_INSIDE:
for i in nearby:
inside = False
# inside = b.polygon.contains(Point(d[i]))
inside = b.polygon.contains(shg.Point(d[i]))
if inside:
break
# for i in range(b.nnodes_outer):
......
......@@ -49,6 +49,7 @@ class Clusters(object):
self.prefix = prefix
#self.list = []
logging.info("Generating clusters %s %s"%(min,max))
self._clusters = [[self.init_cluster(vec2d(i,j))
for j in range(self.n.y)] for i in range(self.n.x)]
# for i in range(self.nx * self.ny):
......
......@@ -636,7 +636,11 @@ if __name__ == "__main__":
if raw_input().lower() != 'y':
sys.exit(-1)
handler = osmparser.OSMContentHandler(valid_node_keys=[])
if parameters.BOUNDARY_CLIPPING:
border = shg.Polygon(parameters.get_clipping_extent())
else:
border = None
handler = osmparser.OSMContentHandler(valid_node_keys=[], border=border)
buildings = Buildings()
buildings.register_callbacks_with(handler)
source = open(osm_fname)
......
......@@ -10,6 +10,7 @@ Use a tool like Osmosis to pre-process data.
import xml.sax
import logging
import unittest
import shapely.geometry as shg
class OSMElement(object):
......@@ -73,8 +74,9 @@ class OSMContentHandler(xml.sax.ContentHandler):
the input file processed by e.g. Osmosis first.
"""
def __init__(self, valid_node_keys):
def __init__(self, valid_node_keys, border):
xml.sax.ContentHandler.__init__(self)
self.border = border
self._way_callbacks = []
self._relation_callbacks = []
self._uncategorized_way_callback = None
......@@ -135,7 +137,10 @@ class OSMContentHandler(xml.sax.ContentHandler):
def endElement(self, name):
if name == "node":
self.nodes_dict[self._current_node.osm_id] = self._current_node
if self.border is None or self.border.contains(shg.Point(self._current_node.lon, self._current_node.lat)):
self.nodes_dict[self._current_node.osm_id] = self._current_node
else:
logging.debug("Ignored Osmid %d outside clipping"%(self._current_node.osm_id))
elif name == "way":
cb = self.find_callback_for(self._current_way.tags, self._way_callbacks)
# no longer filter valid_way_keys here. That's up to the callback.
......
......@@ -40,6 +40,9 @@ BOUNDARY_WEST = 9.54
BOUNDARY_SOUTH = 47.48
BOUNDARY_EAST = 9.58
BOUNDARY_NORTH = 47.50
# Clip all nodes outside the bounding box
BOUNDARY_CLIPPING = True
BOUNDARY_CLIPPING_BORDER_SIZE = 0.25
OSM_FILE = "buildings.osm" # -- file name of the file with OSM data. Must reside in $PREFIX
USE_PKL = False # -- instead of parsing the OSM file, read a previously created cache file $PREFIX/buildings.pkl
......@@ -287,6 +290,13 @@ def get_extent_global():
cmax = vec2d(BOUNDARY_EAST, BOUNDARY_NORTH)
return cmin, cmax
def get_clipping_extent():
rect = [(BOUNDARY_WEST+BOUNDARY_CLIPPING_BORDER_SIZE, BOUNDARY_SOUTH-BOUNDARY_CLIPPING_BORDER_SIZE),
(BOUNDARY_EAST-BOUNDARY_CLIPPING_BORDER_SIZE, BOUNDARY_SOUTH-BOUNDARY_CLIPPING_BORDER_SIZE),
(BOUNDARY_EAST-BOUNDARY_CLIPPING_BORDER_SIZE, BOUNDARY_NORTH+BOUNDARY_CLIPPING_BORDER_SIZE),
(BOUNDARY_WEST+BOUNDARY_CLIPPING_BORDER_SIZE, BOUNDARY_NORTH+BOUNDARY_CLIPPING_BORDER_SIZE)]
return rect
def show():
"""
Prints all parameters as key = value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment