線分と点の最短距離
[code]
points=[]
point = QgsPoint()
point.setX(10)
point.setY(10)
points.append(point)
point = QgsPoint()
point.setX(30)
point.setY(20)
points.append(point)
line = QgsLineString()
line.setPoints(points)
point = QgsPoint()
point.setX(15)
point.setY(10)
p = QgsGeometryUtils.closestPoint(line, point)
p
<QgsPoint: Point (14 12)>
[/code]

iOSのMKMapViewでタイル表示
iOSのMKMapViewでApple Mapではなく他のタイルサーバー(OSM)を使用するにはMKMapViewのオーバーレイ機能を使用する。
[code]
MKMapView *mv = [[[MKMapView alloc]initWithFrame:rect]autorelease];
[mv setMapType:MKMapTypeStandard];
[mv setDelegate:self];
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
overlay.canReplaceMapContent = YES;
[mv addOverlay:overlay level:MKOverlayLevelAboveLabels];
[/code]
[code]
– (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
return nil;
}
[/code]
pyrcc5を実行すると「指定されたモジュールが見つかりません」
QGISと同時にインストールされるpyrcc5.batを実行してもエラーが発生してコンパイルができない
[code]
C:\OSGeo4W\bin>C:\OSGeo4W\apps\Python37\Scripts\pyrcc5.bat
Traceback (most recent call last):
File "C:\OSGeo4W\apps\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\OSGeo4W\apps\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\OSGeo4W\apps\Python37\lib\site-packages\PyQt5\pyrcc_main.py", line 21, in <module>
from PyQt5.QtCore import PYQT_VERSION_STR, QDir, QFile
ImportError: DLL load failed: 指定されたモジュールが見つかりません。
[/code]
‘pyrcc5’ is not recognized as an internal or external commandにずばり答えが記載されている
予め以下のBATを実行してから
[code]
call "C:\Program Files\QGIS 3.0\bin\o4w_env.bat"
call "C:\Program Files\QGIS 3.0\bin\qt5_env.bat"
call "C:\Program Files\QGIS 3.0\bin\py3_env.bat"
[/code]
pyrccコマンドを実行する
[code]
pyrcc5 -o resources.py resources.qrc
[/code]
QGISのシンボル用SVGをサイズ指定してQLIstViewに表示
QGISのシンボル用SVGはStroke,Fillの色や透明度を変更できるように独自の記述になっている。
[code]
<path
d="M 293.39062 35.525391 A 256 256 0 0 0 37.390625 291.52539 A 256 256 0 0 0 293.39062 "
fill="param(fill)"
fill-opacity="param(fill-opacity)"
stroke="param(outline)"
stroke-opacity="param(outline-opacity)"
stroke-width="param(outline-width)"
id="path6220" />
</svg>
[/code]
このSVGファイルをQSvgRendererを使って描画しても正しく描画できないためFillやStrokeを編集してから描画する。
[code]
self.model = QStandardItemModel(self)
fp = open(‘c:\\3Dkaoku\\svg\\circle.svg’, ‘r’)
datas = fp.read()
fp.close()
datas = datas.replace(‘param(fill)’, ‘#000000’)
datas = datas.replace(‘param(fill-opacity)’, ‘1’)
datas = datas.replace(‘param(outline)’, ‘none’)
datas = datas.replace(‘param(outline-opacity)’, ‘0’)
datas = datas.replace(‘param(outline-width)’, ‘0’)
bytearray = datas.encode(encoding=’utf-8′)
bArray = QByteArray(bytearray)
img = QImage(24, 24, QImage.Format_ARGB32)
img.fill(Qt.white)
painter = QPainter(img)
renderer = QtSvg.QSvgRenderer(bArray)
renderer.render(painter)
pix = QPixmap.fromImage(img)
icon = QIcon(pix)
item = QStandardItem(icon, ‘hello’)
self.model.appendRow(item)
self.listView.setIconSize(QSize(200,200))
self.listView.setUniformItemSizes(True)
self.listView.setModel(self.model)
[/code]

QLIstViewにSVGをサイズ指定して表示
QtデザイナでQListViewをダイアログに配置
表示するSVGのサイズは縦横500pix

これを24pixのサイズでListViewに表示
[code]
self.model = QStandardItemModel(self)
img = QImage(24, 24, QImage.Format_ARGB32)
img.fill(Qt.white)
painter = QPainter(img)
renderer = QtSvg.QSvgRenderer(‘c:\\3Dkaoku\\svg\\circle2.svg’)
renderer.render(painter)
[/code]

DSMの値を読み込む
DSM、DEMは標高値を持ったラスタデータ。
DSMは植生等を含んだ標高値、DEMは地表の標高値。
それぞれのセル(画像データのピクセルのようなもの)の値に標高値を持っている。
標高値のみをもっている場合はバンド数=1であり、それ以外にも値を持っていればバンド数=2となる。
バンド数=レイヤ数のようなもの
以下の画像の赤で囲った箇所がセル

QGISで見るとバンド1の値を793という値が見える
この値をPythonで照会するには以下のコードで実行すればよい
[code]
rlayer = QgsRasterLayer("C:\\dsm.tif", "MYDSM")
rlayer.dataProvider().sample(QgsPointXY(-31952.63,-51051.98),1)
(830.0, True)
[/code]
Featureを削除したらエラー!
ShapeFileのFeatureを削除したらREPACKエラーが発生しました。
REPACKエラーはShapeファイルのサイズをコンパクトにする際に発生したようだ!

ちなみに以下が削除のコード
[code]
iface.activeLayer().startEditing()
iface.activeLayer().deleteSelectedFeatures()
iface.activeLayer().commitChanges()
[/code]
削除は以下でもOK
[code]
iface.activeLayer().deleteFeature(2)
[/code]
どうやらテストで使ったShapeファイルが壊れていたみたい!




