python中point什么意思_使用Python的Point中的矩形

您想使用GDAL/OGR/OSR,它可以执行投影,缓冲,甚至可以为您编写Shapefile。

为了将度量lat / long转换为度量缓冲区的米,您需要一个投影坐标系。在下面的示例中,我使用UTM区域,它们是动态加载和缓存的。这将在大地水准面上计算15公里。

我还计算了一个圆形多边形的GIS缓冲区和计算缓冲区的包络,它是你寻找的矩形。

from osgeo import ogr, osr

# EPSG:4326 : WGS84 lat/lon : http://spatialreference.org/ref/epsg/4326/

wgs = osr.SpatialReference()

wgs.ImportFromEPSG(4326)

coord_trans_cache = {}

def utm_zone(lat, lon):

"""Args for osr.SpatialReference.SetUTM(int zone, int north = 1)"""

return int(round(((float(lon) - 180)%360)/6)), int(lat > 0)

# Your data from a text file, i.e., fp.readlines()

lines = ['-43.1234,40.1234\n', '-43.1244,40.1244\n']

for ft, line in enumerate(lines):

print("### Feature " + str(ft) + " ###")

lat, lon = [float(x) for x in line.split(',')]

# Get projections sorted out for that UTM zone

cur_utm_zone = utm_zone(lat, lon)

if cur_utm_zone in coord_trans_cache:

wgs2utm, utm2wgs = coord_trans_cache[cur_utm_zone]

else: # define new UTM Zone

utm = osr.SpatialReference()

utm.SetUTM(*cur_utm_zone)

# Define spatial transformations to/from UTM and lat/lon

wgs2utm = osr.CoordinateTransformation(wgs, utm)

utm2wgs = osr.CoordinateTransformation(utm, wgs)

coord_trans_cache[cur_utm_zone] = wgs2utm, utm2wgs

# Create 2D point

pt = ogr.Geometry(ogr.wkbPoint)

pt.SetPoint_2D(0, lon, lat) # X, Y; in that order!

orig_wkt = pt.ExportToWkt()

# Project to UTM

res = pt.Transform(wgs2utm)

if res != 0:

print("spatial transform failed with code " + str(res))

print(orig_wkt + " -> " + pt.ExportToWkt())

# Compute a 15 km buffer

buff = pt.Buffer(15000)

print("Area: " + str(buff.GetArea()/1e6) + " km^2")

# Transform UTM buffer back to lat/long

res = buff.Transform(utm2wgs)

if res != 0:

print("spatial transform failed with code " + str(res))

print("Envelope: " + str(buff.GetEnvelope()))

# print("WKT: " + buff.ExportToWkt())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值