New answers tagged

1

1) I just don't know how to convert .geojson file to .shp. This is a one of the bases of ogr Python. If you have a geometry, it is very easy to convert it to a shapefile # geojson is GeoJson Polygon from osgeo import ogr output = "geojson.shp" driver = ogr.GetDriverByName('ESRI Shapefile') if os.path.exists(output): driver.DeleteDataSource(output) ...


0

Have a look at my answer to this question: How to speed up raster to polygon conversion in R? In there, I have briefly described how to install Gdal on windows. If you had extra questions feel free to comment here.


1

WKT is only a text markup language for representing vector geometry, therefore you cannot convert 3D WKT to 2D (= text to text), you need to change the geometry The problem with ogr is that it seems that all the geometries are 3D by defaut 1) Creation of a 2D point with ogr point = ogr.Geometry(ogr.wkbPoint) # 2D point point.AddPoint(1198054.34, 648493.09)...


1

There are now Python modules easier to use for that, as rasterio Rasterio employs GDAL to read and writes files using GeoTIFF and many other formats. Its API uses familiar Python and SciPy interfaces and idioms like context managers, iterators, and ndarrays. Therefore from Masking raster with a polygon feature in Rasterio Cookbook import rasterio ...


2

You need to use the -dstalpha option to gdalwarp e.g.: gdalwarp -cutline INPUT.shp -crop_to_cutline -dstalpha INPUT.tif OUTPUT.tif This will add an alpha band to the output tiff which masks out the area falling outside the cutline. P.S. duplicate question


1

GDALinfo is a function in rgdal, and unless you compiled rgdal yourself against that installation of GDAL it won't have HDF4 - presumably you have the CRAN Windows binary, which isn't built with HDF (and some others). gdal_translate is not a function in rgdal, but you don't say what package/s you are using, so I don't know what that is (gdalUtils?). ...


0

I had previously installed fiona using pip. I just reinstalled it using conda : conda install -c anaconda fiona=1.6.0 It solved my problem.


3

To cut an image (tif file) by using GDAL python library, and without gdalwarp utility, you need to find row and column raster indexes of top point [p1=(minX, maxY)] and bottom point [p2=(maxX, minY)]. The formulas, based in your code, are: i1 = int((p1[0] - xOrigin) / pixelWidth) j1 = int((yOrigin - p1[1] ) / pixelHeight) i2 = int((p2[0] - xOrigin) / ...


1

I seem to have resolved one issue, but another still persists so I will ask in another question. I think there were conflicts with 32-bit and 64-bit installs. Since ArcGIS runs python in 32-bit and I am on a 64-bit machine, initially, I assumed I would install the 64-bit builds for GDAL. When I installed the 32-bit versions and their python binaries, ...


0

The table you opened, Value Added, does not have geospatial features. It is meant to be joined to MUPolygons, on the MUKEY field. In your download Soils folder look for a much larger zip file, probably around 1 gigabyte or larger. This file geodatabase contains the Soils polygon, etc. I have QGIS 2.14.3 32bit and I can view all the data layers using the ...


0

There are two problems: 1) you import Fiona twice because GeoPandas use Fiona for reading/writing shapefiles grep -nr "fiona" *.py geocode.py:4:from fiona.crs import from_epsg geodataframe.py:259: >>> import fiona geodataframe.py:260: >>> fiona.supported_drivers geodataframe.py:269: The *kwargs* are passed to fiona....


1

I struggled with this too! I managed to solve the problem ogr2ogr -f MSSQLSpatial "MSSQL:server=Servername\SQL2012;database=DatabaseName;UID= username;PWD=password" C:\Pathto\shape.shp All you need to do is get rid of the [] and it should work...Hope this is still applicable to you.Just to show you I had the same issue here is a screensht of multiple ...


1

This is one of the most common GDAL/OGR Python Gotchas: A dataset is only written to disk after it is closed. Closing a dataset happens when it goes out of scope. This can be done in a number of ways and one of the following needs to be appended to the end of your script. data_out = None data_out = "some new value" del(data_out) There are libraries ...


0

Do the files at the paths filea and fileb exist? Try: filea = r'C:/Users/claudio/workspace/test/test1/rasa.tif' fileb = r'C:/Users/claudio/workspace/test/test1/rasb.tif'


0

This was implemented in RFC59.1 in GDAL release 2.1.0. def BuildVRTOptions(options = [], resolution = None, outputBounds = None, xRes = None, yRes = None, targetAlignedPixels = None, separate = None, bandList = None, addAlpha = None, ...


2

Thats because you are running it from the processing toolbox. Don't know why it happens, but it happens for me too. Try going: Raster (menu at top of the screen) > Projections > Warp You should see the pencil button and be able to edit the GDAL code


5

It is possible if you convert your raster to a vector layer. Quick example, starting from this classification raster: Use Raster > Conversion > Polygonize to convert it to a vector layer: If you want to create points over a whole class (and not over each separate "patch"), use the Vector > Geometry Tools > Singleparts to Multiparts tool. ...


1

You might run into a problem with the antipodal point of the projection. If you clip your raster to the area of validity (that is Europe), it works: gdal_translate -projwin -26 75 44 28 -of GTiff bluemarble.tif bluemarble-Europe.tif gdalwarp -overwrite -s_srs EPSG:4326 -t_srs EPSG:3035 -of GTiff bluemarble-Europe.tif bluemarble-3035.tif You might take ...


2

I think I may have figured it out. If one resets the Nodata value in the original files to -9999 with: gdalwarp -dstnodata -9999 tmean1_16.tif tmean1_16_error999.tif and then uses gdalmerge specifying both the input nodata value and the output nodatavalue: gdal_merge.py -v -n -9999 -a_nodata -9999 -o tmean1_06_16.tif tmean1_06_error999.tif ...


0

I made a solution based on Max Bohnet ideas. In folder /usr/share/qgis/python/plugins/processing/algs/saga/description I found this folders 2.1.2 2.1.3 2.1.4 2.2.0 2.2.2 2.2.3 There is no documentation I found previously about this problem. I supposed every code is a version of saga gis, then I created a new folder 2.2.7 Next, I copied all the ...


0

I guess I found an ugly side of free software here. One side, qgis programers really knows this problem since 10 months ago. They dicieded it is not their responsability to solve this problem and I found they are planning to drop support to SAGA. The other side, SAGA is producing now more frequently new versions. Each new version with different name in ...


0

I found the answer on another thread with some minor tweaks: (Adapted from Yellowcap's answer) Make a virtual environment: virtualenv env source env/bin/activate cd env Download the GDAL package version you want, unzip it and cd into it: pip download GDAL==1.11.2 (or whichever version you want) tar -zxvf GDAL-1.11.2.tar.gz cd GDAL-1.11 According to ...


0

Yellowcap's answer above worked for me with some minor tweaks: pip install --no-install is no longer an option. Instead, inside the env directory: pip download GDAL==1.11.2 (or whichever version you want) Unzip the downloaded directory and cd into it: tar -zxvf GDAL-1.11.2.tar.gz cd GDAL-1.11.2 pip install --no-download is also no longer an option. ...


0

I'd just like to add that checking for Spatialite support via ogrinfo --formats sqlite | grep 'spatialite' -i and an output of SQLite -vector- (rw+v): SQLite / Spatialite does not guarantee support. Mine outputs this but then ogr2ogr still fails claiming it does not support Spatialite. Instead, use ogrinfo --format sqlite | grep 'spatialite' -i (note the ...


-1

I have seen the same problem. In my case the raster and the clip vector are both in the same space so there is no need for a transformation. It worked with earlier versions of GDAL so I suggest regressing to 2.02 and it will work.


0

Another option is to install the Anaconda Python distribution which has packages for GDAL. If you are going to be doing a lot of work using GDAL with other Python packages (scipy, pandas, scikit-learn etc.,) this might be a better option than OSGeo4W. On the other hand if you want to use Python in combination with a number of open source remote sensing and ...


0

@Luke's comment led me to the Python\Lib\site-packages\osgeo folder, and I noticed immediately that it had a directory structure that looked familiar. Two levels further in (in C:\Python27\Lib\site-packages\osgeo\data\gdal) I was looking at all the csv files that GDAL looks for in GDAL_DATA. So, I amended the PATH to include C:\Python27\Lib\site-packages\...


1

I just had this same problem. Including the full path to gdal_calc.py was only part of the solution for me. Using Spyder (Anaconda) with Python 2.7, I had to include the statement: os.system('python path\to\anaconda\python path\to\gdal_calc.py -A filename -B filename --outfile=out.tif --calc=(A+B)') Also note that if using a numpy function in the --calc ...


0

Okay so I found an easy way to do this for anyone interested. Get the bounding box of the Geotif using the command line utility gdalinfo Use osmconvert -b"bottom_left_lat","bottom_left_long","top_left_lat","top_left_long" to extract the geotiff Enjoy your cropped OSM file!


2

Your ArcGIS python is the system default. So when you run a python script without specifying which python to use, the ArcGIS one is used. Don't upgrade the ArcGIS numpy, you can break arcpy. You can run gdal_calc.py using the Anaconda python using something like path\to\anaconda\python path\to\gdal_calc.py etc... If you don't want to do this every ...


3

I would check this one which we have helped creating.


0

For those using the node-gdal bindings for Node.js: const gdal = require('gdal'); const extensions = []; gdal.drivers.forEach(driver => { const exts = driver.getMetadata().DMD_EXTENSIONS; if (exts) { exts.split(' ').forEach(ext => extensions.push(ext)); } });


1

You have installed QGIS with ubuntugis support. https://launchpad.net/~ubuntugis/+archive/ubuntu/ubuntugis-unstable/+packages?field.name_filter=&field.status_filter=published&field.series_filter=trusty reveals that they only have GDAL 1.11.2 for trusty. The ubuntugis stable ppa does not offer a newer version for trusty either. They offer however ...


0

This appears to be an issue with Geoserver and the nodata values in the GeoTIFF file. Opening the file in QGIS an Geoviewer displays the white areas as expected. I have not been able to get Geoserver to display this image properly, however, I've found that creating an image pyramid is both faster and does not produce the colourful artifacts. When I ...


1

Gdal_calc.py manual http://www.gdal.org/gdal_calc.html has an example that might work for you: set values of zero and below to null gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0


1

From memory, the RAT/colour table for a tif is either stored in a .dbf or .aux.xml file. You could try deleting those if they exist.


1

It's been a few months since I posted this. @michael-miles-stimson suggested that the correct way to do this would be to sample points along each edge of the bounding box, project them, then build an encompassing bounding box on those points. The drop-in Python/GDAL code below does this and allows you to select the number of interpolating points you'd like ...


1

My solution was to run a /usr/bin/gdal_calc.py -A input.tif --outfile=output.tif --calc="A*1" --NoDataValue=0 --co="compress=lzw"


0

The issue was resolved in the gdal-dev mailing list, here's how: create the MEM driver and create the mem image with 0 bands Get the pointer to your allocated memory with CPLPrintPointer Use AddBand from the dataset to add the bands e.g. (error checking omitted) unsigned int numbands = 0; char **papszOptions = NULL; GDALDriver *poDriver = ...


5

I have solved the problem. When generating VRT with GDAL I did not use full path for Sentinel2 xml file. This is fine for using gdal_translate etc but causes an error inside PostGIS as full path is required both to the VRT and inside it. Wrong way to generate VRT that will be used as out-of-db raster in PostGIS: gdal_translate -of VRT SENTINEL2_L2A:...


1

In document https://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp the difference is explained in section "Will increasing RAM increase the speed of gdalwarp?" -wm sets the memory reserved for working buffers of gdalwarp, gdal_cachemax is used for setting the size of i/o buffers. There are more technical details in the section "Warp and Cache Memory: Technical ...


0

You must convert the "description" field of your csv file into label annotation following the DGAL OGR Feature Style specification http://www.gdal.org/ogr_feature_style.html. See a text label example from the section 2.1 A text label, taking the text string from the "text_string" attribute field: "LABEL(f:"Times New Roman",s:12pt,t:{text_string})...


1

It looks like GDAL currently does not support georeferencing information in that format: Long Format Name Code Creation Georeferencing Maximum file size Compiled by default ... TerraSAR-X Complex SAR Data Product COSAR No No -- Yes ... The documentation on that format is pretty scarce ...


0

GDAL 2.1-dev seems to make a connection: gdalinfo http://landsat-pds.s3.amazonaws.co m/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B5.TIF Driver: GTiff/GeoTIFF Files: none associated Size is 7621, 7791 Coordinate System is: PROJCS["WGS 84 / UTM zone 45N", GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298....


1

Fixed by downgrading gdal to 1.10.1. Would be nice to know why /vsicurl/ isnt working in more recent versions of gdal, or perhaps I'm doing something wrong.


1

It's actually much simpler than what you've got going on there. ogr2ogr outputShapefile.shp input.kml Of course you can also use other option to specify srs etc. for example I work alot with a non standard crs, Lowrance Mercator Meter, so I use: ogr2ogr -t_srs "+proj=merc +a=6356752.3142 +b=6356752.3142 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=...


0

An important caveat that you omit is, what OS are your using? The function may be parsing the path in a specific way. Have you tried your path without double separators? gdalUtils::gdalinfo("C:/Users/mydirectory/R/MOD13A3.A2015335.h13v03.005.2016007192527.hdf") You should also make sure that you are running the most current version of R and gdalUtils. ...


0

I didn't figure out how to make it work with the gdalwarp, but I downloaded VDatum and did a single point coversion. After which it identified that I needed to use the geoid12b. Then I found in the VDatum directory the geoid12b/*.gtx files. Opened the NED file in gdal and the geoid file in gdal and created a matching projection of the geoid into the NED and ...


2

I got the same error message which was caused by me handing over a numpy matrix (not an array) to np.unique. You can make sure that a (multi-dimensional) array is passed by writing print np.unique(np.array(outArr))


1

You might get unexpected results because your dataset crosses the 180° meridian. As a consequence, the tile is squeezed around the globe when reprojected to WGS84. To avoid that, you have to cut the raster data at the +/- 179.99° meridian. The following batch works with pure GDAL: gdal_translate HDF4_EOS:EOS_GRID:"MOD11A1.A2004091.h34v10.005.2007261231833....



Top 50 recent answers are included