This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBKUtils.py
132 lines (116 loc) · 4.54 KB
/
DBKUtils.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#-------------------------------------------------------------------------------
# Name: DBKUtils
# Purpose: Set of common functions
#
# Author: Anke Keuren (ARIS)
#
# Created: 07-07-2015
# Copyright: (c) ARIS B.V. 2015
# Changes: 04-11-2015, AK:
# - IsNullOrEmpty toegevoegd.
#-------------------------------------------------------------------------------
import os, datetime
from shapefile import *
from shapely.geometry import Point, LineString, Polygon
#-------------------------------------------------------------------------------
def FindField(fields, fieldname):
for index, field in enumerate(fields):
if field[0] == fieldname:
return index
return -1
#-------------------------------------------------------------------------------
def GetTableName(ConnectionString, Separator):
# Delete xxxxData Source= part from Enc_par_table_mdb
TableName = ConnectionString[ConnectionString.lower().find('source=') + 7:]
# Change ! into Separator
TableName = TableName.replace('!', Separator)
return TableName
#-------------------------------------------------------------------------------
def Unquote(s):
s = s.replace('\'', '')
return s.replace('"', '')
#-------------------------------------------------------------------------------
def GeomCentroid(shape):
if shape.shapeType in [5, 15, 25]:
poly = Polygon(shape.points)
polyCentroid = poly.centroid
geom = polyCentroid.__geo_interface__
return geom
else:
return None
#-------------------------------------------------------------------------------
def IsNullOrEmpty(v):
if v is None:
return True
if v == '':
return True
if v == "":
return True
if v == {}:
return True
if v == []:
return True
#-------------------------------------------------------------------------------
def HasNumbers(inputString):
return any(char.isdigit() for char in inputString)
#-------------------------------------------------------------------------------
# Function: SplitsAdres
# Purpose: Splits een adres-regel in straatnaam, huisnummer en letter.
# Parameters: - adres: string
# - result: dictionary
#-------------------------------------------------------------------------------
def SplitsAdres(adres, result):
straat = ""
huisnummer = ""
huisletter = ""
if not HasNumbers(adres):
straat = adres
else:
for c in reversed(adres):
if c.isnumeric():
if len(straat) == 0:
huisnummer = c + huisnummer
else:
straat = c + straat
elif c.isalpha():
if len(huisnummer) == 0:
huisletter = c + huisletter
else:
straat = c + straat
else:
if len(straat) == 0:
huisnummer = c + huisnummer
else:
straat = c + straat
if len(huisletter.strip()) > 0 and len(huisnummer.strip()) == 0:
straat = straat + " " + huisletter
huisletter = ""
result["openbareRuimteNaam"] = straat.strip()
result["huisnummer"] = huisnummer.strip()
result["huisletter"] = huisletter.strip()
#----------------------------------------------------------------------------
def LogStart():
txt = '\n'
txt += '#============================================================================' + '\n'
txt += 'Start Conversie: ' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + '\n'
return txt
#----------------------------------------------------------------------------
def LogEnd():
txt = ''
txt += 'End Conversie : ' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + '\n'
txt += '#============================================================================' + '\n'
return txt
#----------------------------------------------------------------------------
def LogError(msg):
txt = 'Error: ' + msg + '\n'
##txt += '#----------------------------------------------------------------------------' + '\n'
return txt
#----------------------------------------------------------------------------
def LogWarning(msg):
txt = 'Warning: ' + msg + '\n'
##txt += '#----------------------------------------------------------------------------' + '\n'
return txt
#-------------------------------------------------------------------------------
def WriteLogTxt(logFileName,txt):
with open(logFileName,'a') as logfile:
logfile.write(txt)