TransWikia.com

Errors when running python gdal.grid with basic parameters

Geographic Information Systems Asked by will kinsman on March 29, 2021

There are a few problems when I run the following code.

  1. Image comes out flipped vertically, even though lat lon is input correctly
  2. I have to run the code twice for it to run properly (so wierrd)
  3. I also get the following errors:
    ERROR 4: `result.tif' not recognized as a supported file format.
    ERROR 4: Unable to open result.tif to obtain file list.
    ERROR 1: Deleting result.tif failed:
    Permission denied

I use the following data in the points.csv:

    lat lon value
    39.545  -75.78  0.001034494
    39.555  -75.78  0.001033509
    39.565  -75.78  0.001032392
    39.575  -75.78  0.001001829
    39.585  -75.78  0.00094428
    39.595  -75.78  0.000940016
    39.605  -75.78  0.000897172
    39.615  -75.78  0.000896742
    39.625  -75.78  0.000896021

And here is the code…

# create the csv and vrt file
vrt_file = """<OGRVRTDataSource>
    <OGRVRTLayer name="points">
        <SrcDataSource>points.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <GeometryField encoding="PointFromColumns" x="lon" y="lat" z="value"/>
    </OGRVRTLayer>
</OGRVRTDataSource>"""
with open("points.vrt", "w") as f:
    f.write(vrt_file.strip())

# perform gridding and RGB rastering
# for some reason this has to run twice????
gdal.AllRegister()
gdal.Grid('result.tif',
               'points.vrt',
               format='GTiff',
               outputType=gdal.GDT_Float32,
               algorithm='linear:radius=0.5',
               zfield='value')

# plot, comes out flipped on accident
im = gdal.Open('result.tif').ReadAsArray()
im = plt.imshow(im)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP