前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >生成面要素的中心点-GDAL

生成面要素的中心点-GDAL

作者头像
数据处理与分析
发布2019-07-31 17:05:06
2.4K0
发布2019-07-31 17:05:06
举报

啥是GDAL

对于GIS来说,GDAL几乎是万物之源!

QGIS,用了GDAL!

FME,用了GDAL!

ArcGIS,也用了GDAL!

……

具体有多少,可以去官网上去查看,就不再一一列举了!

咋就想到用这个库了呢?

某天,我们的白总在我的QQ群里问了个这样的问题:

并且还不想用商业软件来实现,还要求要用代码!

怎么整!

唉!

谁让他是白总呢!

白总有需求,咱当然要响应了!

于是,就想到了GDAL。

于是,就想:GDAL有没有类似的功能?

答案是:当然有!

所以就打算用GDAL来解决这个问题。

但别问我谁是‘于是’,我也不知道!

做法

搜索引擎的坑

也许是我打开方式有问题吧,我搜索了接近两个小时,百度、必应、谷歌,都试了一遍,但没啥收获!

所以不要过于依赖搜索引擎!

还是官方文档靠谱

搜索无果,我就放弃了搜索引擎。把主要精力放在了官方文档上。看了看文档,我发现了俩函数。经过测试,这俩函数都是可以的。

代码语言:javascript
复制
PointOnSurface(Geometry self) -> Geometry

OGRGeometryH
OGR_G_PointOnSurface(OGRGeometryH hGeom)

Returns a point guaranteed to lie on the surface.

This method relates to the SFCOM ISurface::get_PointOnSurface() method
however the current implementation based on GEOS can operate on other
geometry types than the types that are supported by SQL/MM-Part 3 :
surfaces (polygons) and multisurfaces (multipolygons).

This method is built on the GEOS library, check it for the definition
of the geometry operation. If OGR is built without the GEOS library,
this method will always fail, issuing a CPLE_NotSupported error.

Parameters:
-----------

hGeom:  the geometry to operate on.

a point guaranteed to lie on the surface or NULL if an error occurred.

OGR 1.10

Centroid(Geometry self) -> Geometry

int OGR_G_Centroid(OGRGeometryH hGeom, OGRGeometryH  hCentroidPoint)

Compute the geometry centroid.

The centroid location is applied to the passed in OGRPoint object. The  centroid is not necessarily within the geometry.

This method relates to the SFCOM ISurface::get_Centroid() method  however the current implementation based on GEOS can operate on other  geometry types such as multipoint, linestring, geometrycollection such as  multipolygons. OGC SF SQL 1.1 defines the operation for surfaces  (polygons). SQL/MM-Part 3 defines the operation for surfaces and  multisurfaces (multipolygons).

This function is the same as the C++ method  OGRGeometry::Centroid().

This function is built on the GEOS library, check it for the  definition of the geometry operation. If OGR is built without the GEOS  library, this function will always fail, issuing a CPLE_NotSupported  error.

OGRERR_NONE on success or OGRERR_FAILURE on error.

代码

查完文档,后面的就很简单了,直接上代码吧!

代码语言:javascript
复制
import ogr

p = ogr.CreateGeometryFromWkt('POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 4,4 4,4 2,2 2)) ')

#生成内部点

#方式一

p.PointOnSurface().ExportToWkt()

#方式二

p.Centroid().ExportToWkt()

具体的区别,我还没来得及体会。只知道PointOnSurface生成的点,在面的内部,而Centorid生成的点,不一定在内部!具体的使用,还需日后细细品。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-07-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据处理与分析 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 啥是GDAL
  • 咋就想到用这个库了呢?
  • 做法
    • 搜索引擎的坑
      • 还是官方文档靠谱
      • 代码
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档