Skip to content

Commit

Permalink
v2.3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
warrieka committed Apr 18, 2023
1 parent bd464d7 commit a107b56
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 28 deletions.
82 changes: 82 additions & 0 deletions docs/wcs_test.ipynb
Expand Up @@ -518,6 +518,88 @@
" buf_type=gdal.GDT_Float32)\n",
"scanline"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[1, 2], 4, 5]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f =[[4,54],[1,2],4,5]\n",
"f[1:]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"def fetchElevaton(LineString, srs=31370, samples=20 ):\n",
" baseUri = 'https://dhm.agiv.be/api/elevation/v1/DHMV2'\n",
" locations = \"|\".join( [\"{},{}\".format(*f) for f in LineString ] )\n",
" data = {}\n",
" data[\"SrsIn\"] = srs\n",
" data[\"SrsOut\"] = srs \n",
" data[\"Locations\"] = locations\n",
" data[\"Samples\"] = samples\n",
" resp = requests.get(baseUri, params=data )\n",
" return resp.json()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[0.0, 152898.7, 212780.2, 6.29],\n",
" [82.56850173779661, 152907.77368421055, 212698.1315789474, 7.25],\n",
" [165.13700347559322, 152916.84736842106, 212616.06315789474, 8.21],\n",
" [247.7055052133898, 152925.92105263157, 212533.9947368421, 8.43],\n",
" [330.27400695118644, 152934.9947368421, 212451.9263157895, 7.93],\n",
" [412.84250868898306, 152944.06842105265, 212369.85789473687, 8.54],\n",
" [495.4110104267797, 152953.14210526316, 212287.7894736842, 8.07],\n",
" [577.9795121645762, 152962.21578947367, 212205.72105263156, 8.69],\n",
" [660.5480139023729, 152971.2894736842, 212123.65263157897, 7.09],\n",
" [743.1165156401695, 152980.36315789475, 212041.58421052631, 7.41],\n",
" [825.6850173779661, 152989.4368421053, 211959.51578947366, 7.56],\n",
" [908.2535191157627, 152998.5105263158, 211877.44736842107, 7.23],\n",
" [990.8220208535594, 153007.58421052631, 211795.37894736842, 7.44],\n",
" [1073.3905225913559, 153016.65789473685, 211713.31052631576, 8.28],\n",
" [1155.9590243291525, 153025.73157894737, 211631.24210526314, 7.4],\n",
" [1238.5275260669491, 153034.8052631579, 211549.17368421052, 7.7],\n",
" [1321.0960278047457, 153043.87894736842, 211467.1052631579, 6.73],\n",
" [1403.6645295425424, 153052.95263157896, 211385.03684210527, 6.78],\n",
" [1486.233031280339, 153062.0263157895, 211302.96842105262, 4.21],\n",
" [1568.8015330181356, 153071.1, 211220.9, 5.82]]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ln = [[152898.7,212780.2],[153071.1,211220.9]]\n",
"\n",
"fetchElevaton(ln)"
]
}
],
"metadata": {
Expand Down
58 changes: 45 additions & 13 deletions geopunt/dhm.py
@@ -1,4 +1,5 @@
from typing import Tuple, Iterator
from typing import Tuple, Iterator, Sequence
import numpy as np
from qgis.core import ( QgsRectangle, QgsProject, QgsCoordinateTransform,
QgsPointXY, QgsRasterLayer, QgsRaster, QgsStyle, QgsRasterShader,
QgsColorRampShader, QgsSingleBandPseudoColorRenderer, QgsGeometry)
Expand All @@ -7,13 +8,11 @@

class dhm:
def __init__(self) -> None:
self.dhmlayer = self.dhmLayer()
self.crs = self.dhmlayer.crs()
self.dhmlayer = self.dhmLayer()
self.crs =self.dhmlayer.crs()
self.dhmProvider = self.dhmlayer.dataProvider()
self.nodata = self.dhmProvider.sourceNoDataValue(1)

self.t = QgsCoordinateTransform(self.crs, QgsProject.instance().crs(), QgsProject.instance())

@staticmethod
def dhmLayer(dtm_url=URL_DHM) -> QgsRasterLayer:
f"""
Expand Down Expand Up @@ -41,7 +40,7 @@ def dhmLayer(dtm_url=URL_DHM) -> QgsRasterLayer:
renderer.setOpacity(0.8)

dhmlayer.setRenderer(renderer)
dhmlayer.triggerRepaint()
# dhmlayer.triggerRepaint()
return dhmlayer
return None

Expand All @@ -53,14 +52,16 @@ def identify(self, xy:QgsPointXY, bbox:QgsRectangle=QgsRectangle(), w:int=0, h:i
Returns:
Tuple[float, float, float]: a tuple containing the x,y,z coordinates
"""
pnt= self.t.transform(xy)
_xy= self.t.transform(xy)
_bbox= self.t.transformBoundingBox( bbox )

ident = self.dhmProvider.identify(pnt, QgsRaster.IdentifyFormatValue, boundingBox=bbox, width=w, height=h)
ident = self.dhmProvider.identify(_xy, QgsRaster.IdentifyFormatValue, boundingBox=_bbox, width=w, height=h)

if ident.isValid():
z= ident.results()[1]
if z != self.nodata:
return ( xy.x() , xy.y() , z )
print(z)
return ( xy.x() , xy.y() , None )


Expand All @@ -77,17 +78,48 @@ def identifyLine(self, geom: QgsGeometry, dist:float=50, count:int=None) -> Iter
"""
if geom.wkbType() != 2:
raise Exception("only QgsGeometry of type Line is allowed")

if count is not None:
dist = geom.length() / count
else:
count = geom.length() // dist

print(dist, count)
line = geom.densifyByDistance(dist)
bbox = self.t.transformBoundingBox( geom.boundingBox() )
w= h= count

print(line)
for pnt in line.asPolyline():
yield self.identify(pnt, bbox=bbox, w=w, h=h )
print(pnt)
yield self.identify(pnt, bbox)

def fetchAsArray(self, geom: QgsGeometry, d:float=50, c:int=None) -> Sequence:
"""Identify a series of points along a line. Result is numpy array.
Args:
geom (QgsGeometry): A line geometry
d (float, optional):. The distance at along the line to interpolate a point, ignored if count is set. Defaults to 50.
c (int, optional): The number of points to interpolate. Defaults to None.
Returns:
List: a 4 by c array in form [[d,x,y,z],**]
"""
if geom.wkbType() != 2:
raise Exception("only QgsGeometry of type Line is allowed")

if c is not None:
dist = geom.length() / c
else:
dist = d

self.t = QgsCoordinateTransform( QgsProject.instance().crs(), self.crs, QgsProject.instance())

line = geom.densifyByDistance(dist).asPolyline()
pnt0 = line[0]
x0, y0, z0 = self.identify(pnt0, geom.boundingBox() )
data = [[0, x0, y0, z0]]


for pnt in line[1:]:
x,y,z = self.identify(pnt)
r = np.sqrt( (x-x0)**2 + (y-y0)**2 )
x0, y0, z0 = (x,y,z0)
data.append([r,x,y,z])
return data
18 changes: 6 additions & 12 deletions geopunt4QgisElevation.py
Expand Up @@ -2,8 +2,7 @@
from qgis.PyQt.QtWidgets import (QDialog, QPushButton, QDialogButtonBox, QFileDialog, QSizePolicy,
QToolButton, QColorDialog, QInputDialog)
from qgis.PyQt.QtGui import QIcon, QColor
from qgis.core import (Qgis, QgsRasterLayer, QgsProject, QgsStyle, QgsRasterShader,
QgsColorRampShader, QgsSingleBandPseudoColorRenderer)
from qgis.core import Qgis, QgsProject
from qgis.gui import QgsMessageBar, QgsVertexMarker
from .ui_geopunt4QgisElevation import Ui_elevationDlg

Expand Down Expand Up @@ -90,7 +89,7 @@ def _initGui(self):
self.figure.canvas.mpl_connect('motion_notify_event', self.showGraphMotion)
self.ui.saveLineBtn.clicked.connect(self.saveLineClicked)
self.ui.savePntBtn.clicked.connect(self.savePntClicked)
self.ui.addDHMbtn.clicked.connect(self.addDHMasWCS)
self.ui.addDHMbtn.clicked.connect(lambda: QgsProject.instance().addMapLayer(self.dhm.dhmLayer()) )
self.ui.refreshBtn.clicked.connect( self.onRefresh )
self.ui.buttonBox.helpRequested.connect(self.openHelp)

Expand Down Expand Up @@ -178,7 +177,8 @@ def onResize(self, _):
self.figure.tight_layout()

def openHelp(self):
webbrowser.open_new_tab("http://www.geopunt.be/voor-experts/geopunt-plug-ins/functionaliteiten/hoogteprofiel")
webbrowser.open_new_tab(
"http://www.geopunt.be/voor-experts/geopunt-plug-ins/functionaliteiten/hoogteprofiel")

def drawBtnClicked(self):
self.clean()
Expand Down Expand Up @@ -260,14 +260,7 @@ def setFill( self ):
xdata = np.array( [n[0] for n in self.profile ] ) * self.xscaleUnit[0]
ydata = np.array( [n[3] for n in self.profile ] )
self.ax.fill_between( xdata, ydata, -9999, color=clr.name() )

def addDHMasWCS(self):
if self.dhm.dhmlayer:
QgsProject.instance().addMapLayer(self.dhm.dhmlayer)
else: self.bar.pushMessage("Error",
QCoreApplication.translate("geopunt4QgisElevationDialog", "Kan WCS niet laden"),
level=Qgis.Critical, duration=10)


def plot(self):
if self.Rubberline == None: return

Expand All @@ -276,6 +269,7 @@ def plot(self):
nrSamples = self.ui.nrOfSampleSpin.value()

self.profile = self.elevation.fetchElevaton( lineString, 4326, nrSamples)
self.dhm.fetchAsArray( self.Rubberline.asGeometry(), c=nrSamples )

if np.max( [n[0] for n in self.profile ] ) > 1000: self.xscaleUnit = (0.001 , "km" )
else: self.xscaleUnit = (1 , "m" )
Expand Down
4 changes: 2 additions & 2 deletions metadata.txt
Expand Up @@ -21,15 +21,15 @@ about=NL: "Geopunt voor QGIS" is een plugin voor de QGIS open source desktop GIS
- Search for Parcels
- Search for layers in the geopunt catalog

version=2.3.0.0
version=2.3.0.1
author=Kay Warrie
email=kaywarrie@gmail.com

# end of mandatory metadata

# Optional items:
# Uncomment the following line and add your changelog entries:
changelog=added support for wfs2.0.0
changelog=changed icons, backend services and implemented wcs support in elevation profile.

# tags are comma separated with spaces allowed
tags=INSPIRE, GEOPUNT, GDI, VLAANDEREN, BRUSSEL, BELGIE, ADRES, ADRESSEN, AGIV, GEOLOKATIE, GEOCODE, WEBSERVICE, GRB, CRAB, FLANDERS, BELGIUM, BRUSSELS, LOCATION, ADDRESS, POINT OF INTEREST, POI, URBIS, GIPOD
Expand Down
2 changes: 1 addition & 1 deletion ui_geopunt4QgisElevation.ui
Expand Up @@ -235,7 +235,7 @@
<number>10</number>
</property>
<property name="value">
<number>50</number>
<number>30</number>
</property>
</widget>
</item>
Expand Down

0 comments on commit a107b56

Please sign in to comment.