# pythongdal教程之：几何形状geometry与投影projection

point = ogr.geometry(ogr.wkbpoint)

line = ogr.geometry(ogr.wkblinestring)

line.setpoint(0,30,30) #(10,10) -> (30,30)

print line.getpointcount()

print line.getx(0)

print line.gety(0)

ring = ogr.geometry(ogr.wkblinearring)

ring.closerings()

outring = ogr.geometry(ogr.wkblinearring)

inring = ogr.geometry(ogr.wkblinearring)inring = ogr.geometry(ogr.wkblinearring)

inring.closerings()

polygon = ogr.geometry(ogr.wkbpolygon)

print polygon.getgeometrycount()

outring = polygon.getgeometryref(0)

inring = polygon.getgeometryref(1)

multipoint = ogr.geometry(ogr.wkbmultipoint)

point = ogr.geometry(ogr.wkbpoint)point = ogr.geometry(ogr.wkbpoint)

spatialref = layer.getspatialref()

spatialref = geom.getspatialreference()

•importfromwkt()

•importfromepsg()

•importfromproj4()

•importfromesri()

•importfrompci(, ,

)

•importfromusgs(, )

•importfromxml()

•exporttowkt()

•exporttoprettywkt()

•exporttoproj4()

•exporttopci()

•exporttousgs()

•exporttoxml()

sourcesr = osr.spatialreference()

sourcesr.importfromepsg(32612) #utm 12n wgs84

targetsr = osr.spatialreference()

targetsr.importfromepsg(4326) #geo wgs84

coordtrans = osr.coordinatetransformation(sourcesr, targetsr)

geom.transform(coordtrans)

targetsr.morphtoesri()

file = open(‘test.prj’, ‘w’)

file.write(targetsr.exporttowkt())

ffile.close()

Posted in 未分类