Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from hhnk-git/sprint-2.0
Browse files Browse the repository at this point in the history
Sprint 2.0
  • Loading branch information
bastiaan-roos authored May 2, 2019
2 parents 298fbf0 + ad7bab5 commit 5f83306
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 625 deletions.
4 changes: 2 additions & 2 deletions qt_models/area_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{'field': 'selected', 'show': False, 'field_type': CHECKBOX_FIELD, 'column_width': 50,
'single_selection': True},
{'field': 'hover', 'show': False, 'field_type': CHECKBOX_FIELD, 'column_width': 50},
{'field': 'weight', 'header': 'omvang', 'column_width': 50},
{'field': 'distance', 'header': 'afstand', 'column_width': 50},
{'field': 'weight', 'header': 'prioriteit', 'column_width': 50},
{'field': 'distance', 'header': 'afstand', 'column_width': 50, 'show': False},
)


Expand Down
2 changes: 1 addition & 1 deletion qt_models/legger_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, data_dict, feature):
'selected_variant_id': 'geselecteerde_variant',
'begroeiingsvariant_id': 'begroeiingsvariant_id',
'selected_begroeiingsvariant_id': 'geselecteerde_begroeiingsvariant',
'selected_remarks': 'selectie_opmerkingen',
'selected_remarks': 'opmerkingen',
}

# set default values
Expand Down
62 changes: 36 additions & 26 deletions sql_models/legger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_or_create(session, model, defaults=None, **kwargs):
class BegroeiingsVariant(Base):
__tablename__ = 'begroeiingsvariant'

id = Column(Integer(), primary_key=True, autoincrement=True)
id = Column(Integer(), primary_key=True, autoincrement=True, index=True)
naam = Column(String(20))
friction = Column(Float())
is_default = Column(Boolean, default=False)
Expand All @@ -48,7 +48,7 @@ class Waterdeel(Base):
__tablename__ = 'waterdeel'
extend_existing = True

id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, index=True)
shape_length = Column(Float)
shape_area = Column(Float)
geometry = Column("GEOMETRY", Geometry(geometry_type='MULTIPOLYGON', srid=28992))
Expand All @@ -62,7 +62,7 @@ class HydroObject(Base):
__tablename__ = 'hydroobject'
extend_existing = True

id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, index=True)
geometry = Column("GEOMETRY", Geometry(geometry_type='MULTILINESTRING', srid=28992))
code = Column(String(50), index=True)
categorieoppwaterlichaam = Column(Integer)
Expand All @@ -72,8 +72,9 @@ class HydroObject(Base):
flowline_id = Column(Integer) # link to 3di id
score = Column(Float)
begroeiingsvariant_id = Column(Integer,
ForeignKey(BegroeiingsVariant.__tablename__ + ".id"))

ForeignKey(BegroeiingsVariant.__tablename__ + ".id"),
index=True)
opmerkingen = Column(String())
# shape_length = Column(Float)

profielen = relationship("Profielen",
Expand Down Expand Up @@ -103,7 +104,6 @@ class HydroObject(Base):
# primaryjoin="Varianten.begroeiingsvariant_id == BegroeiingsVariant.id",
uselist=False)


def __str__(self):
return u'Hydro object {0}'.format(
self.code)
Expand All @@ -112,12 +112,13 @@ def __str__(self):
class Profielen(Base):
__tablename__ = 'profielen'

id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, index=True)
proident = Column(String(24))
bron_profiel = Column(String(50))
pro_id = Column(Integer, index=True)
hydro_id = Column(Integer,
ForeignKey(HydroObject.__tablename__ + ".id"))
ForeignKey(HydroObject.__tablename__ + ".id"),
index=True)
# shape_lengte = Column(Float)
hydro = relationship(HydroObject,
back_populates="profielen")
Expand All @@ -134,7 +135,7 @@ def __str__(self):
class Profielpunten(Base):
__tablename__ = 'profielpunten'

objectid = Column(Integer, primary_key=True, autoincrement=True)
objectid = Column(Integer, primary_key=True, autoincrement=True, index=True)
pbp_id = Column(Integer)
prw_id = Column(Integer)
pbpident = Column(String(24))
Expand All @@ -143,7 +144,8 @@ class Profielpunten(Base):
iws_hoogte = Column(Float)
afstand = Column(Float)
pro_pro_id = Column(Integer,
ForeignKey(Profielen.__tablename__ + '.pro_id'))
ForeignKey(Profielen.__tablename__ + '.pro_id'),
index=True)
geometry = Column("GEOMETRY", Geometry(geometry_type='POINT', srid=28992))

profiel = relationship(
Expand All @@ -158,7 +160,7 @@ def __str__(self):
class Kenmerken(Base):
__tablename__ = 'kenmerken'

id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, index=True)
diepte = Column(Float)
bron_diepte = Column(String(50))
bodemhoogte = Column(Float)
Expand All @@ -170,8 +172,8 @@ class Kenmerken(Base):
grondsoort = Column(String(50))
bron_grondsoort = Column(String(50))
hydro_id = Column(Integer,
ForeignKey(HydroObject.__tablename__ + ".id"))

ForeignKey(HydroObject.__tablename__ + ".id"),
index=True)
na_lengte = Column(Float)
voor_lengte = Column(Float)
new_category = Column(Integer)
Expand All @@ -188,18 +190,21 @@ def __str__(self):
class Varianten(Base):
__tablename__ = 'varianten'

id = Column(String(), primary_key=True)
id = Column(String(), primary_key=True, index=True)
begroeiingsvariant_id = Column(Integer,
ForeignKey(BegroeiingsVariant.__tablename__ + ".id"))
diepte = Column(Float)
ForeignKey(BegroeiingsVariant.__tablename__ + ".id"),
index=True)
diepte = Column(Float,
index=True)
waterbreedte = Column(Float)
bodembreedte = Column(Float)
talud = Column(Float)
# maatgevend_debiet = Column(Float)
verhang_bos_bijkerk = Column(Float)
opmerkingen = Column(String())
hydro_id = Column(Integer,
ForeignKey(HydroObject.__tablename__ + ".id"))
ForeignKey(HydroObject.__tablename__ + ".id"),
index=True)

begroeiingsvariant = relationship(BegroeiingsVariant,
# foreign_keys='begroeiingsvariant_id',
Expand Down Expand Up @@ -230,11 +235,12 @@ class GeselecteerdeProfielen(Base):

hydro_id = Column(Integer,
ForeignKey(HydroObject.__tablename__ + ".id"),
primary_key=True)
primary_key=True,
index=True)
variant_id = Column(String(),
ForeignKey(Varianten.__tablename__ + ".id"))
ForeignKey(Varianten.__tablename__ + ".id"),
index=True)
selected_on = Column(DateTime, default=datetime.datetime.utcnow)
opmerkingen = Column(String())

hydro = relationship(HydroObject,
back_populates="geselecteerd")
Expand All @@ -248,8 +254,12 @@ class ProfielFiguren(Base):

# object_id = Column(Integer, primary_key=True)
hydro_id = Column('id_hydro', Integer,
ForeignKey(HydroObject.__tablename__ + ".id"))
profid = Column(String(16), ForeignKey(Varianten.__tablename__ + ".id"), primary_key=True, )
ForeignKey(HydroObject.__tablename__ + ".id"),
index=True)
profid = Column(String(16),
ForeignKey(Varianten.__tablename__ + ".id"),
primary_key=True,
index=True)
type_prof = Column(String(1))
coord = Column(String())
peil = Column(Float)
Expand Down Expand Up @@ -282,7 +292,7 @@ class DuikerSifonHevel(Base):
__tablename__ = 'duikersifonhevel'
extend_existing = True

id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, index=True)
geometry = Column("GEOMETRY", Geometry(geometry_type='MULTILINESTRING', srid=28992))
code = Column(String(50), index=True)
categorie = Column(Integer)
Expand All @@ -294,9 +304,9 @@ class DuikerSifonHevel(Base):
vormkoker = Column(Float)
# shape_lengte = Column(Float)

debiet = Column(Float) # extra?
channel_id = Column(Integer) # extra?
flowline_id = Column(Integer) # extra?
debiet = Column(Float) # extra
channel_id = Column(Integer) # extra
flowline_id = Column(Integer) # extra

def __str__(self):
return u'DuikerSifonHevel {0}'.format(
Expand Down
23 changes: 11 additions & 12 deletions sql_models/legger_views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def create_legger_views(session):
session.execute(
"""
DROP VIEW IF EXISTS hydroobjects_kenmerken4;
DROP VIEW IF EXISTS hydroobjects_kenmerken;
"""
)

session.execute(
"""
CREATE VIEW hydroobjects_kenmerken4 AS
CREATE VIEW hydroobjects_kenmerken AS
SELECT
h.id,
code,
Expand All @@ -27,7 +27,7 @@ def create_legger_views(session):
geselecteerd_breedte,
geselecteerde_variant,
geselecteerde_begroeiingsvariant,
selectie_opmerkingen,
h.opmerkingen,
CASE
WHEN h.debiet >= 0 THEN "GEOMETRY"
WHEN h.debiet THEN ST_REVERSE("GEOMETRY")
Expand Down Expand Up @@ -64,31 +64,30 @@ def create_legger_views(session):
v.diepte as geselecteerd_diepte,
v.waterbreedte as geselecteerd_breedte,
v.id as geselecteerde_variant,
v.begroeiingsvariant_id as geselecteerde_begroeiingsvariant,
g.opmerkingen as selectie_opmerkingen
v.begroeiingsvariant_id as geselecteerde_begroeiingsvariant
FROM geselecteerd g, varianten v
WHERE g.variant_id = v.id) as sel
ON sel.hydro_id = h.id
""")

session.execute(
"""
DELETE FROM views_geometry_columns WHERE view_name = 'hydroobjects_kenmerken3';
DELETE FROM views_geometry_columns WHERE view_name = 'hydroobjects_kenmerken';
"""
)

session.execute(
"""
INSERT INTO views_geometry_columns (view_name, view_geometry, view_rowid, f_table_name,
f_geometry_column, read_only)
VALUES('hydroobjects_kenmerken4', 'geometry', 'id', 'hydroobject', 'geometry', 1);
VALUES('hydroobjects_kenmerken', 'geometry', 'id', 'hydroobject', 'geometry', 1);
""")

session.execute(
"""
INSERT INTO views_geometry_columns (view_name, view_geometry, view_rowid, f_table_name,
f_geometry_column, read_only)
VALUES('hydroobjects_kenmerken4', 'line', 'id', 'hydroobject', 'geometry', 1);
VALUES('hydroobjects_kenmerken', 'line', 'id', 'hydroobject', 'geometry', 1);
""")

session.commit()
Expand Down Expand Up @@ -151,13 +150,13 @@ def create_legger_views(session):

session.execute(
"""
DROP VIEW IF EXISTS begroeiingsadvies4;
DROP VIEW IF EXISTS begroeiingsadvies;
"""
)

session.execute(
"""
CREATE VIEW begroeiingsadvies4 AS
CREATE VIEW begroeiingsadvies AS
SELECT
bv.naam as advies_naam,
a.*
Expand Down Expand Up @@ -245,15 +244,15 @@ def create_legger_views(session):

session.execute(
"""
DELETE FROM views_geometry_columns WHERE view_name = 'begroeiingsadvies4';
DELETE FROM views_geometry_columns WHERE view_name = 'begroeiingsadvies';
"""
)

session.execute(
"""
INSERT INTO views_geometry_columns (view_name, view_geometry, view_rowid, f_table_name,
f_geometry_column, read_only)
VALUES('begroeiingsadvies4', 'geometry', 'id', 'hydroobject', 'geometry', 1);
VALUES('begroeiingsadvies', 'geometry', 'id', 'hydroobject', 'geometry', 1);
""")


Expand Down
19 changes: 14 additions & 5 deletions utils/geom_collections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections import OrderedDict


# use fiona collection for 'normal' use


Expand Down Expand Up @@ -101,7 +102,6 @@ def keys(self, start=0, stop=None, step=1, **kwds):
qbbox = QgsRectangle(*bbox)
selected.intersection_update(set(self._spatial_index.intersects(qbbox)))


if mask:
# todo
pass
Expand Down Expand Up @@ -129,16 +129,25 @@ def writerecords(self, records):
for record in records:
record['id'] = nr
self.ordered_dict[nr] = record
geom = shape(record['geometry'])

# rtree
# self._spatial_index.insert(nr, geom)
# QGIS:
feature = QgsFeature()
feature.setFeatureId(nr)
qgeom = QgsGeometry()
qgeom.fromWkb(geom.to_wkb())
feature.setGeometry(qgeom)
try:
geom = shape(record['geometry'])
qgeom = QgsGeometry()
qgeom.fromWkb(geom.to_wkb())

except:
wkt = "{}({})".format(
record['geometry']['type'],
",".join(["{} {}".format(*c) for c in record['geometry']['coordinates']]))
qgeom = QgsGeometry()
qgeom.fromWkt(wkt)

feature.setGeometry(qgeom)
self._spatial_index.insertFeature(feature)
nr += 1

Expand Down
2 changes: 1 addition & 1 deletion utils/legger_map_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_layer(spatialite_path, table_name, geom_column=''):

layer = get_layer(
self.path_legger_db,
'hydroobjects_kenmerken4',
'hydroobjects_kenmerken',
geometry_col)

# todo: remove this filter when bidirectional islands are supported
Expand Down
4 changes: 2 additions & 2 deletions utils/map_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def add_layers_to_map(self):
]),
('tbv begroeiingsgraad', [
('aanwijzen', 'hydroobject', 'begroeiingsvariant_id', 'begroeiingsvariant', 'geometry', None),
('begroeiingsadvies', 'begroeiingsadvies4', 'advies_id', 'begroeiingsvariant', 'geometry', None),
('begroeiingsvariant', 'begroeiingsadvies4', 'aangew_bv_id', 'begroeiingsvariant',
('begroeiingsadvies', 'begroeiingsadvies', 'advies_id', 'begroeiingsvariant', 'geometry', None),
('begroeiingsvariant', 'begroeiingsadvies', 'aangew_bv_id', 'begroeiingsvariant',
'geometry', None),
# ('sterk min profiel', 'ruimte_view', 'ruim', 'min_max_line', 'geometry', None),
# ('ruimte', 'ruimte_view', 'over_width', 'min_max_line', 'geometry', None),
Expand Down
Loading

0 comments on commit 5f83306

Please sign in to comment.