A very good starting point to implement a raster to point script using Python and GDAL is the "Raster to vector line" recipe: https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html#raster-to-vector-line
You just have to modify (simplify) the array2shp method. I guess it's easier than to implement the gdal2org tool in Python.
EDIT:
I modified the "Raster to vector line" recipe to get a raster to point script. I tested the script with a 5000x5000 16bit gray scale Image and it's very slow. I would recommend the script only for small rasters.
import ogr, gdal, osr, os
import numpy as np
import itertools
def pixelOffset2coord(raster, xOffset,yOffset):
geotransform = raster.GetGeoTransform()
originX = geotransform[0]
originY = geotransform[3]
pixelWidth = geotransform[1]
pixelHeight = geotransform[5]
coordX = originX+pixelWidth*xOffset
coordY = originY+pixelHeight*yOffset
return coordX, coordY
def raster2array(rasterfn):
raster = gdal.Open(rasterfn)
band = raster.GetRasterBand(1)
array = band.ReadAsArray()
return array
def array2shp(array,outSHPfn,rasterfn):
# max distance between points
raster = gdal.Open(rasterfn)
geotransform = raster.GetGeoTransform()
pixelWidth = geotransform[1]
# wkbPoint
shpDriver = ogr.GetDriverByName("ESRI Shapefile")
if os.path.exists(outSHPfn):
shpDriver.DeleteDataSource(outSHPfn)
outDataSource = shpDriver.CreateDataSource(outSHPfn)
outLayer = outDataSource.CreateLayer(outSHPfn, geom_type=ogr.wkbPoint )
featureDefn = outLayer.GetLayerDefn()
outLayer.CreateField(ogr.FieldDefn("VALUE", ogr.OFTInteger))
# array2dict
point = ogr.Geometry(ogr.wkbPoint)
row_count = array.shape[0]
for ridx, row in enumerate(array):
if ridx % 100 == 0:
print "{0} of {1} rows processed".format(ridx, row_count)
for cidx, value in enumerate(row):
Xcoord, Ycoord = pixelOffset2coord(raster,cidx,ridx)
point.AddPoint(Xcoord, Ycoord)
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(point)
outFeature.SetField("VALUE", int(value))
outLayer.CreateFeature(outFeature)
outFeature.Destroy()
outDS.Destroy()
def main(rasterfn,outSHPfn):
array = raster2array(rasterfn)
array2shp(array,outSHPfn,rasterfn)
if __name__ == "__main__":
rasterfn = r'D:\test.tif'
outSHPfn = r'D:\test.shp'
main(rasterfn,outSHPfn)