ogr 缓冲区_OGR几何关系与操作
OGR幾何關系與操作
關系
本文腳本需要導入ogr模塊
from osgeo import ogr
Equals
兩個幾何的邊界、內(nèi)部和外部重合
a1=ogr.CreateGeometryFromWkt("POINT(1 1)")
a2=ogr.CreateGeometryFromWkt("POINT(1 1)")
print(a1.Equals(a2)) # True
Contains
幾何包含另一個幾何的內(nèi)部和邊界,并且邊界不接觸,適用于所有幾何類型,并且a.Contains(b)==b.Within(a)
p=ogr.CreateGeometryFromWkt("POLYGON((0 0,0 2,2 2,2 0,0 0))")
l=ogr.CreateGeometryFromWkt("LINESTRING(0.5 0.5,1.5 1.5)")
a=ogr.CreateGeometryFromWkt("POINT(0.5 0.5)")
b=ogr.CreateGeometryFromWkt("POINT(1 1)")
c=ogr.CreateGeometryFromWkt("POINT(1.5 1.5)")
print(p.Contains(l)) # True
print(p.Contains(a)) # b,c True
print()
print(l.Contains(a)) # False
print(l.Contains(b)) # True
print(l.Contains(c)) # False
print()
print(a.Within(l)) # False
print(b.Within(l)) # True
print(c.Within(l)) # False
點的邊界為空,線的邊界就是線的兩個端點,因此線不包含本身的兩個端點,多邊形的邊界是組成邊界的線。
Crosses
幾何與另一個幾何內(nèi)部相交,但不包含它,且相交的維度小于其中一個幾何的維度,適用于線–>線,線–>面。
p=ogr.CreateGeometryFromWkt("POLYGON((0 0,0 2,2 2,2 0,0 0))")
l1=ogr.CreateGeometryFromWkt("LINESTRING(1 1,3 2)")
l2=ogr.CreateGeometryFromWkt("LINESTRING(2 3,3 1)")
print(l1.Crosses(p)) # True
print(l1.Crosses(l2)) # True
Disjoint
兩個幾何邊界、內(nèi)部都不相交
a1=ogr.CreateGeometryFromWkt("POINT(0 0)")
a2=ogr.CreateGeometryFromWkt("POINT(1 1)")
print(a1.Disjoint(a2)) # True
Touches
兩個幾何邊界相交,內(nèi)部不相交
l1=ogr.CreateGeometryFromWkt("LINESTRING(4 2,3 1)")
l2=ogr.CreateGeometryFromWkt("LINESTRING(3 1,2 2)")
p1=ogr.CreateGeometryFromWkt("POLYGON((0 0,0 1,1 1,2 0,0 0))")
p2=ogr.CreateGeometryFromWkt("POLYGON((1 1,1 2,2 2,2 0,1 1))")
print(l1.Touches(l2)) # True
print(p1.Touches(p2)) # True
print(l2.Touches(p2)) # True
Intersects
兩個幾何的Contains、Crosses、Equals、Touches、Within其中一個為True,則為True
Overlaps
兩個多邊形相交,但相互不包含
p1=ogr.CreateGeometryFromWkt("POLYGON((0 0,0 3,3 3,3 0,0 0))")
p2=ogr.CreateGeometryFromWkt("POLYGON((1 1,1 2,2 2,2 1,1 1))")
p3=ogr.CreateGeometryFromWkt("POLYGON((2 1,2 2,4 2,4 1,2 1))")
print(p2.Overlaps(p1)) # False
print(p3.Overlaps(p1)) # True
操作
Buffer
緩沖區(qū)
l=ogr.CreateGeometryFromWkt("LINESTRING(0 0,1 1)")
print(l.ExportToJson())
buffer=l.Buffer(0.5)
Boundary
提取邊界
p=ogr.CreateGeometryFromWkt("POLYGON((0 0,1 2,3 1,2 0,0 0))")
print(p.ExportToJson())
boundary=p.Boundary()
print(boundary.ExportToJson())
# { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 1.0, 2.0 ], [ 3.0, 1.0 ], [ 2.0, 0.0 ], [ 0.0, 0.0 ] ] ] }
# { "type": "LineString", "coordinates": [ [ 0.0, 0.0 ], [ 1.0, 2.0 ], [ 3.0, 1.0 ], [ 2.0, 0.0 ], [ 0.0, 0.0 ] ] }
Intersection
相交
p1=ogr.CreateGeometryFromWkt("POLYGON((0 0,1 2,3 1,2 0,0 0))")
p2=ogr.CreateGeometryFromWkt("POLYGON((0 0,1 2,3 1,2 0,0 0))")
p1.Intersection(p2)
SymDifference
對稱差
p1.SymDifference(p2)
Difference
相減
p1.Difference(p2)
p2.Difference(p1)
Union
p1.Union(p2)
Envelope
最小外包矩形
p=ogr.CreateGeometryFromWkt("POLYGON((0 0,1 2,3 1,2 0,0 0))")
envelope=p.GetEnvelope()
print("envelope:",envelope)
# envelope: (0.0, 3.0, 0.0, 2.0)
總結(jié)
以上是生活随笔為你收集整理的ogr 缓冲区_OGR几何关系与操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fragment重叠问题
- 下一篇: Sublime插件安装