Commit a929077c authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

attempt to fix coastline holes

parent 7d06fb68
...@@ -24,13 +24,16 @@ def storetree(): ...@@ -24,13 +24,16 @@ def storetree():
sections = [] sections = []
jsonsections = [] jsonsections = []
for line in lines: for i, line in enumerate(lines):
if len(section) == 10: if len(section) == 100:
sections.append(LineString(section)) sections.append(LineString(section))
jsonsections.append(section) jsonsections.append(section)
section = [] section = []
if '-999999' in line: if '-999999' in line:
if len(section) > 1: #this will skip some points where section will end with only one coord. Possibly create a line from previous section on ending point if len(section) == 1: #create a line from previous section on ending point
split = lines[i-1].split(' ')
section.append([float(split[2]),float(split[1])])
if len(section) > 0:
sections.append(LineString(section)) sections.append(LineString(section))
jsonsections.append(section) jsonsections.append(section)
section = [] section = []
...@@ -38,9 +41,9 @@ def storetree(): ...@@ -38,9 +41,9 @@ def storetree():
split = line.split(' ') split = line.split(' ')
section.append([float(split[2]),float(split[1])]) section.append([float(split[2]),float(split[1])])
print('Number of lines: '+str(len(sections))) print('Number of lines: '+str(len(sections)))
with open('resources/strtree.pickle', 'wb') as dumphandle: # with open('resources/strtree.pickle', 'wb') as dumphandle:
print('HIGHEST_PROTOCOL :'+str(pickle.HIGHEST_PROTOCOL)) # print('HIGHEST_PROTOCOL :'+str(pickle.HIGHEST_PROTOCOL))
pickle.dump(sections, dumphandle, protocol=pickle.HIGHEST_PROTOCOL) # pickle.dump(sections, dumphandle, protocol=pickle.HIGHEST_PROTOCOL)
with codecs.open('resources/strtree.json', 'w', 'utf8') as jsonhandle: with codecs.open('resources/strtree.json', 'w', 'utf8') as jsonhandle:
jsonhandle.write(json.dumps(jsonsections, sort_keys = True, ensure_ascii=False)) jsonhandle.write(json.dumps(jsonsections, sort_keys = True, ensure_ascii=False))
...@@ -51,12 +54,12 @@ def storetree(): ...@@ -51,12 +54,12 @@ def storetree():
def loadtree(): def loadtree():
try: try:
with open('resources/strtree.pickle', 'rb') as picklehandle: # with open('resources/strtree.pickle', 'rb') as picklehandle:
# tree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle'))))) # # tree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
tree = STRtree(pickle.load(picklehandle)) # tree = STRtree(pickle.load(picklehandle))
queryline = LineString([[57.5,17.5],[57.5,18.5]]) # queryline = LineString([[57.5,17.5],[57.5,18.5]])
matches = tree.query(queryline); # matches = tree.query(queryline);
print('Number of pickle matches: '+str(len(matches))) # print('Number of pickle matches: '+str(len(matches)))
with open('resources/strtree.json', 'r') as jsonhandle: with open('resources/strtree.json', 'r') as jsonhandle:
#jsondata = json.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.json')))); #jsondata = json.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.json'))));
jsondata = json.load(jsonhandle); jsondata = json.load(jsonhandle);
...@@ -72,9 +75,6 @@ def loadtree(): ...@@ -72,9 +75,6 @@ def loadtree():
print_exc() print_exc()
sys.exit(1) sys.exit(1)
# # tree = STRtree(sections)
def read_properties(filepath, sep='=', comment_char='#'): def read_properties(filepath, sep='=', comment_char='#'):
props = {} props = {}
try: try:
...@@ -148,6 +148,6 @@ def run(): ...@@ -148,6 +148,6 @@ def run():
To run in terminal call with python __init__.py To run in terminal call with python __init__.py
''' '''
if __name__ == "__main__": if __name__ == "__main__":
#storetree() # storetree()
loadtree() loadtree()
\ No newline at end of file
This diff is collapsed.
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