0

I have a large csv file of 3 columns of x y and z values. I want to do the following: 1. How to convert that csv into vector shape file (points). 2. How to convert the obtained points in step 2 into geo raster. 3. Lets say a set of separate point file in "shp" format how to extract the values from the raster obtained in step 2 into new the csv file so I can perform so statistics on it.

The issue is that I'm new to geo-processing using python, for example for step 2 I used to do that easily in R using "raster" package and for step 3 also using "extract" function in "raster" package. However, in python I can do step 2 in geopandas but step 2 and 3 no simple answer is available.

3
  • The normal procedure is converting directly XYZ to Raster. With GDAL tha's trivial. Commented Jun 16, 2019 at 10:21
  • Can you explain more? Commented Jun 19, 2019 at 22:14
  • gis.stackexchange.com/questions/254330/… Commented Jun 20, 2019 at 13:30

1 Answer 1

1

This exact case exists in the GDAL documentation.

Assuming your data, dem.csv, is like:

Easting,Northing,Elevation
86943.4,891957,139.13
87124.3,892075,135.01
86962.4,892321,182.04
87077.6,891995,135.01
...

You create a VRT to describe it:

<OGRVRTDataSource>
    <OGRVRTLayer name="dem">
        <SrcDataSource>dem.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <GeometryField encoding="PointFromColumns" x="Easting" y="Northing" z="Elevation"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

Or, if the CSV lacks columns, you can specify your GeometryField like this:

<GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>

Save that as something likedem.vrt for use in later commands.

Then to interpolate with gdal_grid and produce a GeoTIFF output:

gdal_grid -a invdist:power=2.0:smoothing=1.0 -txe 85000 89000 -tye 894000 890000 -outsize 400 400 -of GTiff -ot Float64 -l dem dem.vrt dem.tiff
Sign up to request clarification or add additional context in comments.

8 Comments

The issue here is 1. the output is somehow vertically flipped ...2. using python API it produce 512kb Tiff and 3. How to modify the coordinates system for the faster and 4. How to speed the python gdal API because it's extremely slow compared to R
I'm not recommending the use of Python.
Then what language we use ?
It's possible to use the GDAL Python bindings as you have been; I just don't like them. The last block of code is simply the command line; the others are snippets of text files.
How about GMT how to use it to grid the csv file
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.