2019年3月8日星期五

qgis orientedMinimumBoundingBox bug

qgis的实现,以下是该功能在GitHub上源代码的路径: QGIS/src/core/geometry/qgsgeometry.cpp

opencv轮廓检测

https://blog.csdn.net/A632189007/article/details/78126588


import cv2
# 读取图片
img = cv2.imread("PM.png")
# 转灰度图片
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)

# 轮廓检测
_ ,contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

# 新打开一个图片,我这里这张图片是一张纯白图片
newImg = cv2.imread("aaa.png")
newImg = cv2.resize(newImg, (800,800))

# 画图
cv2.drawContours(newImg, contours, -1, (0,0,0), 3)

# 展示 cv2.imshow("img", newImg) cv2.waitKey(0)

2019年3月7日星期四

2019年3月6日星期三

论文题目


  1. 最小旋转矩形(用来简化桥墩断面)
  2. 黄良铁路对小清河分洪区的影响
  3. 地形沉降对滏阳河中游洼地运用的影响
  4. 地方坐标系与国家坐标系之间近似转换的方法
  5. 如何将大量的桥墩放入mike21模型
  6. 优化qgis的Oriented Minimum Bounding Box算法

 Oriented Minimum Bounding Box strange behavior #33532

is-oriented-minimum-bounding-box-in-qgis-working-correctly 

  1. 永定河卢梁段洪水位的计算、选取
  2. 常用一维水位推算软件实现的区别

最小面积外接矩形( Minimum bounding rectangle )

Finding minimum-area-rectangle for given points?

python opencv minAreaRect 生成最小外接矩形

旋转卡壳——凸多边形最小面积外接矩形

cv2.minAreaRect()

http://dwoll.de/rexrepos/posts/diagBounding.html

qgis Oriented Minimum Bounding Box   
ps:qgis的计算结果,明显有问题,不是想要的结果,不如arcgis的理想

whitebox的算法:
whitebox
MinimumBoundingRectangle.java

qgis的算法:
qgsgeometry.cpp

QgsGeometry QgsGeometry::orientedMinimumBoundingBox

2019年2月24日星期日

mike生成的dbf表头有问题

mike生成的dbf文件,
有的列表头是一样的,
arcgis可以打开,但使用org2ogr会出错。
如果用arcgis 修改过这个文件,arcgis会修改同名的表头,在表头后加后缀。


L:\ldxy__shape>ogr2ogr -sql "select ST_Centroid(geometry),* from YOU_20_XianZhuang" -dialect sqlite centroid_YOU_20_XianZhuang.shp  YOU_20_XianZhuang.shp

ERROR 1: Cannot create virtual table for layer 'YOU_20_XianZhuang' :
CREATE VIRTUAL: invalid SQL statement :
CREATE TABLE "YOU_20_XianZhuang"("Maximum wa" FLOAT,
                                 "Time at ma" FLOAT,
                                 "Maximum cu" FLOAT,
                                 "Time at ma" FLOAT,
                                 "Duration a" FLOAT,
                                 OGR_STYLE VARCHAR HIDDEN,
                                 "GEOMETRY" BLOB_POLYGON_XY_4548,
                                 OGR_NATIVE_DATA VARCHAR,
                                 OGR_NATIVE_MEDIA_TYPE VARCHAR)

ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(select ST_Centroid(geometry),* from YOU_20_XianZhuang):
  no such table: YOU_20_XianZhuang

2019年2月23日星期六

在ogr2ogr命令中使用sql

0、对于表头有空格的情况,可以在sql查询中使用[]将表头包起来,使用单引号或者双引号 会引起不必要的麻烦
How to select a column name with a space in MySQL

1、计算polygon.shp中每个多边形的形心,输出到centroid.shp
ogr2ogr -sql "SELECT ST_Centroid(geometry), * FROM polygon" -dialect sqlite centroid.shp polygon.shp

2、选择水深大于5.0的多边形(注意命令行中单引号、双引号的使用)
ogr2ogr -sql ' SELECT * FROM centroid WHERE "Maximum cu">5.0 ' test.shp centroid.shp

3、输出点的xy坐标
ogr2ogr -sql "SELECT ST_X(geometry) as X, ST_Y(geometry) as Y, * FROM countries_centroid" -dialect sqlite -f CSV out.csv countries_centroid.shp

或者:
ogr2ogr -f CSV output.csv  -lco GEOMETRY=AS_XY countries_centroid.shp

更新:2019-02-25,经实践,使用以下流程较好:
 (1)先生成点文件
ogr2ogr -sql "select ST_Centroid(geometry),* from WU_20" -dialect sqlite centroid_WU_20.shp  WU_20.shp
(2)再将点文件转换为CSV文件
ogr2ogr -dialect sqlite -sql "select ST_X(geometry) as centroid_X, ST_Y(geometry) as centroid_Y, [Maximum wa] as H from centroid_WU_50" -f CSV point_centroid_WU_50.csv  centroid_WU_50.shp