I've been working on a data that is in .tif raster format. I need to convert that into a points shapefile (.shp) to proceed. I went through GDAL in Python but there's only gdal.Polygonize(). So how do I convert it into a points .shp?
I've used this code so far:
from osgeo import gdal,ogr
import sys
import os
gdal.UseExceptions()
os.chdir(path)
src_ds = gdal.Open("IND_ppp_2015_v2.tif")
if src_ds is None:
print ("Unable to open Worldpop data")
sys.exit(1)
try:
srcband = src_ds.GetRasterBand(1)
drv = ogr.GetDriverByName("ESRI Shapefile")
dst_ds = drv.CreateDataSource(dst_layername + ".shp")
dst_layer = dst_ds.CreateLayer(dst_layername,srs = None)
gdal.Polygonize(srcband, None,dst_layer, -1,[],callback = None)
Can you suggest a way to convert into points .shp?
Best Answer
I'd use GDAL and OGR utilities as library functions (if possible):
First, I'd convert the GeoTIFF into the XYZ format (very close to CSV). Then I'd rename the .xyz file to .csv and finally convert the CSV file to ESRI Shapefile.