forked from pnorman/ogr2osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geom.py
67 lines (61 loc) · 1.86 KB
/
geom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2013 Paul Norman
# Released under the MIT license, as given in the file LICENSE, which must
# accompany any distribution of this code.
# Classes
class Geometry(object):
elementIdCounter = 0
elementIdCounterIncr = -1
geometries = []
def __init__(self):
self.id = getNewID()
self.parents = set()
Geometry.geometries.append(self)
def replacejwithi(self, i, j):
pass
def addparent(self, parent):
self.parents.add(parent)
def removeparent(self, parent, shoulddestroy=True):
self.parents.discard(parent)
if shoulddestroy and len(self.parents) == 0:
Geometry.geometries.remove(self)
# Helper function to get a new ID
def getNewID():
Geometry.elementIdCounter += Geometry.elementIdCounterIncr
return Geometry.elementIdCounter
class Point(Geometry):
def __init__(self, x, y):
Geometry.__init__(self)
self.x = x
self.y = y
def replacejwithi(self, i, j):
pass
class Way(Geometry):
def __init__(self):
Geometry.__init__(self)
self.points = []
def replacejwithi(self, i, j):
self.points = [i if x == j else x for x in self.points]
j.removeparent(self)
i.addparent(self)
class Relation(Geometry):
def __init__(self):
Geometry.__init__(self)
self.members = []
def replacejwithi(self, i, j):
self.members = [(i, x[1]) if x[0] == j else x for x in self.members]
j.removeparent(self)
i.addparent(self)
class Feature(object):
features = []
def __init__(self):
self.geometry = None
self.tags = {}
Feature.features.append(self)
def replacejwithi(self, i, j):
if self.geometry == j:
self.geometry = i
j.removeparent(self)
i.addparent(self)