diff --git a/README.md b/README.md index 5217b48..7cdff01 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,9 @@ options: Split ways with more than the specified number of nodes. Defaults to 1800. Any value below 2 - do not split. + --consider-elevation If nodes have the same (X,Y) coordinates but different + Z-levels (e.g, different elevation), then they will be + given different node IDs (default: False) --id ID ID to start counting from for the output file. Defaults to 0. --idfile IDFILE Read ID to start counting from from a file. @@ -199,6 +202,7 @@ osmdata = ogr2osm.OsmData(translation_object) # - max_points_in_way: --split-ways parameter # - add_bounds: --add-bounds parameter # - start_id: --id parameter +# - consider_elevation: --consider-elevation parameter osmdata.process(datasource) # 7. Instantiate either ogr2osm.OsmDataWriter or ogr2osm.PbfDataWriter and diff --git a/ogr2osm/ogr2osm.py b/ogr2osm/ogr2osm.py index e643ce2..0552ad8 100755 --- a/ogr2osm/ogr2osm.py +++ b/ogr2osm/ogr2osm.py @@ -96,6 +96,11 @@ def parse_commandline(logger): parser.add_argument("--split-ways", dest="maxNodesPerWay", type=int, default=1800, help="Split ways with more than the specified number of nodes. " + "Defaults to %(default)s. Any value below 2 - do not split.") + parser.add_argument("--consider-elevation", dest="considerElevation", action="store_true", + help="If nodes have the same (X,Y) coordinates but different Z-levels " + + "(e.g, different elevation), " + + "then they will be given different node IDs " + + "(default: %(default)s)") # ID generation options parser.add_argument("--id", dest="id", type=int, default=0, help="ID to start counting from for the output file. " + @@ -266,7 +271,7 @@ def main(): osmdata = OsmData(translation_object, \ params.roundingDigits, params.maxNodesPerWay, params.addBounds, \ - params.id, params.positiveId) + params.id, params.positiveId, params.considerElevation) osmdata.load_start_id_from_file(params.idfile) diff --git a/ogr2osm/osm_data.py b/ogr2osm/osm_data.py index 57128e6..587335e 100644 --- a/ogr2osm/osm_data.py +++ b/ogr2osm/osm_data.py @@ -18,7 +18,7 @@ class OsmData: def __init__(self, translation, rounding_digits=7, max_points_in_way=1800, add_bounds=False, \ - start_id=0, is_positive=False): + start_id=0, is_positive=False, consider_elevation=False): self.logger = logging.getLogger(__program__) # options @@ -26,6 +26,7 @@ def __init__(self, translation, rounding_digits=7, max_points_in_way=1800, add_b self.rounding_digits = rounding_digits self.max_points_in_way = max_points_in_way self.add_bounds = add_bounds + self.consider_elevation = consider_elevation self.__bounds = OsmBoundary() self.__nodes = [] @@ -83,14 +84,17 @@ def __round_number(self, n): return int(round(n * 10**self.rounding_digits)) - def __add_node(self, x, y, tags, is_way_member): + def __add_node(self, x, y, tags, is_way_member, z=None): rx = self.__round_number(x) ry = self.__round_number(y) + rz = self.__round_number(z) if self.consider_elevation and z else None # TODO deprecated unique_node_id = None if is_way_member: unique_node_id = (rx, ry) + if rz is not None: + unique_node_id = (rx, ry, rz) else: unique_node_id = self.translation.get_unique_node_identifier(rx, ry, tags) # to be replaced by @@ -129,7 +133,7 @@ def __add_relation(self, tags): def __parse_point(self, ogrgeometry, tags): - return self.__add_node(ogrgeometry.GetX(), ogrgeometry.GetY(), tags, False) + return self.__add_node(ogrgeometry.GetX(), ogrgeometry.GetY(), tags, False, z=ogrgeometry.GetZ()) def __parse_multi_point(self, ogrgeometry, tags): @@ -183,8 +187,8 @@ def __parse_linestring(self, ogrgeometry, tags): nodes = [] potential_duplicate_ways = [] for i in range(ogrgeometry.GetPointCount()): - (x, y, z_unused) = ogrgeometry.GetPoint(i) - node = self.__add_node(x, y, {}, True) + (x, y, z) = ogrgeometry.GetPoint(i) + node = self.__add_node(x, y, {}, True, z=z) if previous_node_id is None or previous_node_id != node.id: if previous_node_id is None: # first node: add all parent ways as potential duplicates