-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeshes_from_shapefile.py
More file actions
76 lines (62 loc) · 2.45 KB
/
meshes_from_shapefile.py
File metadata and controls
76 lines (62 loc) · 2.45 KB
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
'''
Mesh test
=========
This demonstrates the use of a mesh mode to distort an image. You should see
a line of buttons across the bottom of a canvas. Pressing them displays
the mesh, a small circle of points, with different mesh.mode settings.
'''
import geopandas
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.graphics import Mesh
from kivy.core.window import Window
from functools import partial
from math import cos, sin, pi
class ROI:
def __init__(self):
self.lon_max = 9.1091775 # 1014029 # easternmost longitude
self.lon_min = 9.0995835 # 1012961 # westernmost longitude
self.lon_diff = self.lon_max - self.lon_min
self.lat_max = 54.1962362 # 7207409 # northermost latitude
self.lat_min = 54.1884733 # 7205932
self.lat_diff = self.lat_max - self.lat_min
class MeshTestApp(App):
def coords_to_point(self, coord, wid):
x = (coord[0] - roi.lon_min) * (roi.lon_max) * Window.size[0]
y = (coord[1] - roi.lat_min) * (roi.lat_max) * Window.size[1]
return x, y
def change_mode(self, mode, *largs):
self.mesh.mode = mode
def build_mesh(self, wid, coords):
""" returns a Mesh of a rough circle. """
vertices = []
indices = []
for i, coord in enumerate(coords):
x, y = self.coords_to_point(coord, wid)
vertices.extend([x, y, 0, 0])
# indices.append(i)
print(x,y)
return Mesh(vertices=vertices, indices=indices)
def build(self):
wid = Widget()
gdf = geopandas.read_file("/home/dunland/github/qScope/data/GIS/Shapefiles/bestandsgebaeude_export.shp")
with wid.canvas:
# geom = gdf.loc[0, 'geometry']
for polygon in gdf['geometry']:
self.mesh = self.build_mesh(wid, polygon.exterior.coords)
# self.mesh.mode = mode
layout = BoxLayout(size_hint=(1, None), height=50)
for mode in ('triangle_fan', 'points', 'line_strip', 'line_loop', 'lines',
'triangle_strip'):
button = Button(text=mode)
button.bind(on_release=partial(self.change_mode, mode))
layout.add_widget(button)
root = BoxLayout(orientation='vertical')
root.add_widget(wid)
root.add_widget(layout)
return root
if __name__ == '__main__':
roi = ROI()
MeshTestApp().run()