Quantcast
Channel: Question and Answer » gdal
Viewing all 397 articles
Browse latest View live

How to install GDAL with Python on windows?

$
0
0

Can anyone please explain to me in step by step instructions how to install GDAL/OGR with Python on Windows. I have Windows Vista and I have tried following the information on the website and it does not seem to bind the exe files for me.

So, if someone would be so kind to walk me through the process, including links to the files/folders I will need I would be happy to do a screen cast to continue to share this with the rest of the world.

thanks in advance

–20100930 update–
I have now tried to run the gdal setup with minGW, but this has also failed:

GDAL_FAIL


Split Big geotiff file and crop it to single file with gdal [on hold]

$
0
0

I need to split big geotiff file to smaller geotiff files so I can deal with it.
I also need to crop from these files.
The map that cropped could be combine from several field.
If anyone deal with similar problem I would be glad to hear about it.

CentOS 6.5 – After compiling gdal.so: Unable to load dynamic library

$
0
0

CentOS release 6.5 (Final)
Linux version 2.6.18-028stab101.1 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)

I’m trying to Install Cartaro CMS (http://cartaro.org/). GeoServer, Postgresql and PostGIS are up and running.

The only missing software requirement to install Cantaro is the GDAL-PHP extension. I’ve spend hours to resolve the dependencies but after successfully compiling the gdal.so, “make test” fails with the following warning:

PHP Warning: PHP Startup: Unable to load dynamic library ‘/tmp/php5-gdal-0.1.3/modules/gdal.so’ – /tmp/php5-gdal-0.1.3/modules/gdal.so: undefined symbol: _ZN17GDALDriverManager10MoveDriverEP10GDALDriveri in Unknown on line 0

  • PHP_SAPI : cli
  • PHP_VERSION : 5.4.36
  • ZEND_VERSION: 2.4.0
  • PHP_OS : Linux – Linux 268.xxx.de 2.6.18-028stab101.1
  • INI actual : /tmp/php5-gdal-0.1.3/tmp-php.ini
  • More .INIs :
  • CWD : /tmp/php5-gdal-0.1.3
  • Extra dirs :
  • VALGRIND : Not used

  • SKIP Test: OGRGeometry [tests/ogrgeometry.phpt]

  • FAIL Test: Version number [tests/version.phpt]

I’ve compiled the actual stable vesions of gdal (1.9.2) and proj4 (4.8.0) by following these instructions:

https://github.com/wavded/ogre/wiki/Compiling-a-recent-ogr2ogr-from-source-on-CentOS-%28RHEL%29

Thanks in advance.

Working with rasters in file geodatabase (.gdb) with GDAL

$
0
0

I’m working on a tool that converts raster layers to arrays for processing with NumPy, and ideally I would like to be able to work with rasters that come packaged in a .gdb without exporting them all (especially if this requires engaging ArcGIS or ArcPy).

Is this possible with the OpenFileGDB driver? From what I can tell this driver seems to treat raster layers the same as vector layers, which gives you access to some data about the layer but doesn’t give you the ReadAsArray functionality.

Problem with Leaflet Boundary Canvas plugin

$
0
0

I’m trying to identify the source of a problem that I’m having, I cannot show a tile layer(created with gdal2tiles) inside a polygon generated in Leaflet, using the plug-in BoundaryCanvas(https://github.com/aparshin/leaflet-boundary-canvas)

Some facts:

  • The tile layer created with Gdal2tiles.py, can be shown in the map with Leaflet if I just use the object tileLayer. From this I understand that the tile layer was generated correctly.

  • If I use the object tileLayer.BoundaryCanvas(with boundary a polygon), the tile is not shown and in the browser there are errors missing PNG files(it’s trying to download png’s that are not in the path structure of the tile layer).

  • If I use the same plug-in with for example the TMS from OSM http://{s}.tile.osm.org/{z}/{x}/{y}.png, it works properly I can show that tile
    inside the polygon.

At this point I don’t know if the errors comes from the Leaflet plug-in or from the tile layer generation, any idea about how to find out would be pretty much appreciated.

I’m using:

  • gdal2tiles.py –profile=geodetic -z 0-15 -w none ./terra.tif

  • gdalinfo:

Driver: GTiff/GeoTIFF

Files: TerraColor_SanFrancisco_US_15m.tif

Size is 7204, 7204

Coordinate System is:

GEOGCS["WGS 84",

DATUM["WGS_1984",

    SPHEROID["WGS 84",6378137,298.257223563,

        AUTHORITY["EPSG","7030"]],

    AUTHORITY["EPSG","6326"]],

PRIMEM["Greenwich",0],

UNIT["degree",0.0174532925199433],

AUTHORITY["EPSG","4326"]]

Origin = (-122.809804036593036,38.285436652047451)

Pixel Size = (0.000138800000000,-0.000138800000000)

Metadata:

AREA_OR_POINT=Area

Image Structure Metadata:

INTERLEAVE=PIXEL

Corner Coordinates:

Upper Left (-122.8098040, 38.2854367) (122d48'35.29"W, 38d17' 7.57"N)

Lower Left (-122.8098040, 37.2855215) (122d48'35.29"W, 37d17' 7.88"N)

Upper Right (-121.8098888, 38.2854367) (121d48'35.60"W, 38d17' 7.57"N)

Lower Right (-121.8098888, 37.2855215) (121d48'35.60"W, 37d17' 7.88"N)

Center (-122.3098464, 37.7854791) (122d18'35.45"W, 37d47' 7.72"N)

Band 1 Block=7204x1 Type=Byte, ColorInterp=Red

Band 2 Block=7204x1 Type=Byte, ColorInterp=Green

Band 3 Block=7204x1 Type=Byte, ColorInterp=Blue

eliminate small polygons of a PNG with gdal_sieve

$
0
0

I want to eliminate polygons wich consist of less than 3550 px in this PNG . I tried using gdal_sieve but there seems to be an error.

gdal_sieve -st 3550 E8.png -of PNG E8sieve3550_4.png
ERROR 6: GDALDriver::Create() ... no create method implemented for this format.

Traceback (most recent call last):
  File "C:PROGRA~1QGISBR~1bingdal_sieve.py", line 165, in <module>
    dst_ds.SetGeoTransform( src_ds.GetGeoTransform() )
AttributeError: 'NoneType' object has no attribute 'SetGeoTransform'

I also tried “PNG” instead of PNG and changed the order of the parameters..

Edit: I tried what user30184 suggested: leave out the -of PNG part so that the output is a .tiff picture. But the result is a bit strange.

Here ist the output of gdalinfo E8.png (which I used as the source image):

Driver: PNG/Portable Network Graphics
Files: E8.png
Size is 8250, 4090
Coordinate System is `'
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 4090.0)
Upper Right ( 8250.0,    0.0)
Lower Right ( 8250.0, 4090.0)
Center      ( 4125.0, 2045.0)
Band 1 Block=8250x1 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=8250x1 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=8250x1 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=8250x1 Type=Byte, ColorInterp=Alpha

After eliminating the small polygons I would like to use “convert E8.png -type palette -colors 256 E8-palette-256colors.png” and than gdal_polygonize..

merging GeoTiffs with GDAL causes grid-like artifacts

$
0
0

I’m processing ASTER DEM tiles, merging them into larger blocks (to minimize visible tile edges) and importing the contours into a postgis database. Workflow:

gdal_merge.py -of GTiff -o merged.tif tile1.tif tile2.tif
gdal_contour -i 10 -a ele -snodata -9999 merged.tif contours.shp
ogr2ogr -f PostgreSQL -nln srtm4 -append -t_srs 'EPSG:3785' contours.shp

For some reason the resulting “merged” contours have grid-like artifacts:

enter image description here

When I skip the merge step and process the same two GeoTiffs separately, there are no artifacts. I’ve tried merging with gdalbuildvrt and got the same grid effect. Why is this happening? How can I avoid this? Thanks in advance.

artifacts in SRTM contour layers processed with GDAL tools and rendered with mapnik

$
0
0

Here is my workflow for importing individual SRTM tiles into postgis using the GDAL utils and rendering a png using mapnik:

  1. gdal_fillnodata.py -srcnodata -32768
  2. gdal_contour -i 10 -a ele -snodata -32768
  3. ogr2ogr -f PostgreSQL -nln srtm3 -append -t_srs ‘EPSG:900913′
  4. (some SQL to split the data into 10m, 50m and 250m tables)
  5. nik2img.py [stylesheet] [file] –srs 900913 -d [width] [height] –no-open -f png -v –center [center] –zoom [zoom]“

Most of the time this works perfectly. However, large areas with mountainous terrain are often completely distorted:
enter image description here

enter image description here

Huge swaths of landscape are covered with strange (often linear) patterns that shouldn’t be there. No way the SRTM data is that messed up. What am I doing wrong? How can I avoid this? Ideally there should be a command-line solution. Thanks in advance!


Color scaling for raster images(batch?)

$
0
0

Let’s say I have raster images and I want to change their color based on their data value(color scaling). If the data values are from -(all negative value) – 0, I want to have that colored Blue. If the data values are from 0 – 0.5, I want to have that colored Light Blue. If the data values are from 0.5 – 1, I want to have that colored Orange. If the data values are from 1 – >1 , I want to have that colored Red. And if there are nodata I wan to have that colored Black. Will that be possible in gdal? And process that in batch?

Error running polygonize from QGIS!

$
0
0

I’m trying to vectorize a raster image and when I’m running polygonize within QGIS 2.6.1. I’m getting the following message:

Traceback (most recent call last): File
“C:PROGRA~1QGISBR~1bingdal_polygonize.py”, line 36, in import
gdal, ogr, osr ImportError: No module named gdal

I know that gdal is installed.
I don’t know what to do! Need help!

In qgis using python, how can I get multiple pixels from a raster based on a vector point file

$
0
0

I just started working with qgis, and for the life of me I cannot figure out how to solve this problem:
I have several points of interest, these are stored in a shape file (just simple points). I have (for now) one raster file with values. What I want to do basically is select those cells in my raster that are near the points in the shape file (I want several window-sizes, like first only one cell, than 9 (3×3), than 25 (5×5) etc). I want to average these cells and get the median and stdev.

I want to do this in a python script, since I will probably have to do this again (and again) at some point. I am new to qgis, but in ArcGis I would have tried converting my points to a raster, and ‘grow’ this raster while calculating zonal statistics.
However since in qgis it should be easier to get data-level access, I was hoping to avoid all that and just convert my points to a position in a raster, and than loop over the values using python. I already figured out how to get to the data using ReadAsArray:

raster = gdal.Open(inputRaster)

band = raster.GetRasterBand(1)

data = band.ReadAsArray()

However I am not sure how (if it is even possible once the data is converted to an array) to link the positions in my shape file to the position in the array. If this is not possible is there another strategy I should consider?
Any help would really really be appreciated.

gdal_polygonize ignores some polygons

$
0
0

I want to polygonize this PNG. I try

gdal_polygonize pic.png -f “GeoJSON” polygonized.geojson

but I get only 11 polygons instead of more than 20. What is the cause or how can I fix it?

EPSG Equidistant cylindrical

$
0
0

I need to know what is the epsg code for equidistant cylindrical because i have to georeference an image Aquarius using gdal_translate

Install QGIS on Ubuntu with GDAL built from source?

$
0
0

I am trying to install QGIS on Ubuntu 14.04. While I can easily install it via the package manager or apt-get, I find that QGIS, when installed, does not have Python support as expected. The symptoms of this include:

  • “Analysis Tools” are missing.
  • “Plugins” > “Python Console” results in nothing happening.
  • In “Plugin Manager” under “Settings” I see the message “The settings on this tab are only applicable for Python Plugins. No Python support detected, thus no settings available.”

The reason I expect Python support to be included is because:

  1. Python is installed (which python yields /usr/bin/python)
  2. GDAL 1.11.0 was installed from source with Python support (After ./configure --with-python, I see SWIG Bindings: python in the output)
  3. gdal is imported within Python just fine (e.g., import gdal works fine)

When I try to install QGIS, apt-get recommends gdal-bin (and gdal-python), which I don’t want to install because I’ve already built GDAL from source with Python support. The same things happens if I try to install only python-qgis. Thus, I believe the problem is that the QGIS package cannot find GDAL, with its Python bindings, on my system. I have bypassed the installation of the gdal-bin package via:

sudo apt-get install --no-install-recommends qgis qgis-plugin-grass

This is what gets me to the conditions described in the bulleted list at the top (no Python support).

I’ve poked around on our StackExchange and not found anyone dealing specifically with the issue of aligning a QGIS package and GDAL built from source. I even tried building QGIS from source; although it recognized my GDAL installation I could not successfully finish the build. Any idea how I can get QGIS to recognize my current GDAL installation and its Python bindings?

How to fix “Unable to load GdalTools plugin. The required ”osgeo [python-gdal]“ module is missing.”

$
0
0

When I start QGIS, it display error message:
Unable to load GdalTools plugin.
The required “osgeo [python-gdal]” module is missing.
Install it and try again.

Couldn't load plugin 'processing' from ['/usr/share/qgis/python', '/home/notroot/.qgis2/python', '/home/notroot/.qgis2/python/plugins', '/usr/share/qgis/python/plugins', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/share/qgis/python/plugins/fTools/tools']

enter image description here

I am using QGIS 2.6 and Ubuntu 12.04!

This is the packages I have installed:

dpkg -l | grep qgis

 ii  libqgis-analysis2.6.1            2.6.1-1precise1       QGIS - shared analysis library
 ii  libqgis-core2.6.1                2.6.1-1precise1       QGIS - shared core library
 ii  libqgis-customwidgets            2.6.1-1precise1       QGIS custom widgets for Qt Designer 
 ii  libqgis-gui2.6.1                 2.6.1-1precise1       QGIS - shared gui library
 ii  libqgis-networkanalysis2.6.1     2.6.1-1precise1       QGIS - shared network analysis library 
 ii  libqgisgrass2.6.1                2.6.1-1precise1       QGIS - shared grass library 
 ii  libqgispython2.6.1               2.6.1-1precise1       QGIS - shared Python library 
 ii  python-qgis                      2.6.1-1precise1       Python bindings to QGIS 
 ii  python-qgis-common               2.6.1-1precise1       Python bindings to QGIS - architecture-independent files 
 ii  qgis                             2.6.1-1precise1       Geographic Information System (GIS) 
 ii  qgis-common                      2.6.1-1precise1       QGIS - architecture-independent data 
 ii  qgis-plugin-globe                2.6.1-1precise1       OSG globe plugin for QGIS 
 ii  qgis-plugin-globe-common         2.6.1-1precise1       OSG globe plugin for QGIS - architecture-independent data 
 ii  qgis-plugin-grass                2.6.1-1precise1       GRASS plugin for QGIS 
 ii  qgis-plugin-grass-common         2.6.1-1precise1       GRASS plugin for QGIS - architecture-independent data 
 ii  qgis-providers                   2.6.1-1precise1       collection of data providers to QGIS 
 ii  qgis-providers-common            2.6.1-1precise1       collection of data providers to QGIS - architecture-independent files
 ii  qgis-server                      2.6.1-1precise1       QGIS server providing various OGC services

Update (from comment):

dpkg -l | grep gdal returns

1.10.0-1~precise2 
ii  libgdal-dev     1.10.0-1~precise2                       Geospatial Data Abstraction Library - Development files
rc  libgdal1-1.7.0  1.7.3-6ubuntu3                          Geospatial Data Abstraction Library
ii  libgdal1h       1.10.0-1~precise2                       Geospatial Data Abstraction Library
ii  python-gdal     1.10.0-1~precise2                       Python bindings to the Geospatial Data Abstraction Library
ii  python3-gdal    1.10.0-1~precise2                       Python 3 bindings to the Geospatial Data Abstraction ibrary

Set coordinate origin to the top left corner

$
0
0

I have a BMP-picture and I know that it’s top left corner has the EPSG:3068 coordinates 35500,24390. I would like to use gdal_polygonize and than calculate the EPSG:3068 coordinates of the produced polygons. But for that I need gdal_polygonize to assume that the top left corner is (0,0) or I need to know at which pixel the actual (0,0) is.
gdalinfo of the picture:

Driver: BMP/MS Windows Device Independent Bitmap
Files: E8256.bmp
Size is 8250, 4090
Coordinate System is `'
Origin = (-1890.000000000000000,1890.000000000000000)
Pixel Size = (3780.000000000000000,-3780.000000000000000)
Corner Coordinates:
Upper Left  (   -1890.000,    1890.000)
Lower Left  (   -1890.000,-15458310.000)
Upper Right (31183110.000,    1890.000)
Lower Right (31183110.000,-15458310.000)
Center      (15590610.000,-7728210.000)
Band 1 Block=8250x1 Type=Byte, ColorInterp=Palette
  Color Table (RGB with 256 entries)
    0: 0,0,0,255
    1: 128,0,0,255
    ...

as you can see the top left corner is -1890,1890. I want that to become 0,0 OR to know at wich pixel 0,0 is. (Pixel size is the length of 1 pixel in coordinates right?)

GDAL (or other open-source) equivalent of Arc's Point To Raster Tool

$
0
0

I’m trying to convert a python script that relies on arcpy into one that only relies on open source modules, but I’m having some trouble. The bulk of my processing lies in one Arc tool “Point to Raster.” The goal is to take a csv file with lat/long coords and turn it into a raster, where each cell value is the number of points contained within that cell. When I’m able to use arcpy, the workflow looks like this:

Make XY event layer from csv of points -->
Use Event layer as input in Point To Raster tool, with cell assignment = COUNT, specifying spatial extent and cellsize -->
Mask out NoData values -->
Write output to .tif

This works fine, and gives me my desired result, but now I need to write the same script without arcpy. I’ve found gdal tools that work for everything except the main process: Point to Raster. Do you know of any gdal utility (or reluctantly, some other open source tool) that could do what Arc’s Point to Raster tool is doing? The 2 gdal tools that look like they could possibly accomplish this are:

  1. gdal_grid (http://www.gdal.org/gdal_grid.html)
    -This tool isn’t meant to do exactly what I want it to do, although it does take a set of points (could be a shapefile, or a csv written as a VRT**) and turn it into a raster grid. I can specify the extent of the gridd along with its resolution, which is important. There is also an option to set grid cell values based on data metrics, with ‘count’ being one of them. However, under the count metric it states “A number of data points found in grid node search ellipse.” What does ‘grid node search ellipse’ mean? Can I not assign values based on a number of data points found in each grid cell’? Is there a difference?

  2. gdal_rasterize (http://www.gdal.org/gdal_rasterize.html)
    -This one looks a little less promising, or maybe that’s just because I don’t entirely understand it. In summary, the tool “burns vector geometries (points, lines and polygons) into the raster band(s) of a raster image,” which sounds like what I need, although there is no keyword to specify point count as the value to be burned, so I don’t know.

A few more things:

  • **I was going to test using gdal_grid, but can’t find anywhere how to convert a CSV to a VRT in python. I know it’s possible by hand, every tutorial/help page I can find says something like: “Say you have a CSV with lat/long, you can write a VRT file for that CSV” then jumps right into “Here’s what the VRT file looks like for the CSV.” But HOW do I write this VRT file, in python? Several pages say to download an FW toolkit (or something) to create the CSV, but I need to do this within python as I’m automating the process for hundreds of CSVs. I tried ogr2ogr but got the error: “VRT driver does not support data source creation,” so I’m at a loss. I could convert the csv to shapefile or some other OGR-recognized format, but the VRT is appealing because the shapefile/whatever that would be created would be very, very large and probably take a while to create. Which leads me to…

  • Each csv has an obsenely large amount of points: ~78 million. So python/numpy won’t even read them without crashing. Additionally, the resulting raster will be global with fine resolution (1km), so a hack that manipulates the coordinates or loops through the points/cells is out of the question.

I’m not sure if I should put my CSV to VRT question in a separate thread, so my apologies if this is too much for one question.

Thoughts/suggestions?

Thanks!

Using OGR2OGR with LIBKML (Examples please)

$
0
0

I am trying to figure out how to use GDAL (ogr2ogr) to export spatial data from SQLServer to KML. The standard KML driver works, but it is not very robust. LIBKML has so much promise (layers, styling, etc), but I cannot find any examples of how to make use of this added functionality.

For example, this works:

ogr2ogr.exe -f LIBKML z.kml "MSSQL:server=box;database=main;trusted_conneciton=yes;tables=dbo.z" -where "state='DE'"

It exports a POINT from my table. I would like to customize labels, icons (color, scale and image) and balloon text. I would also like to create folders/layers.

Ideally, I’d love to use columns like “icon_scale” and “layer_name” in my source tables to control this customization …

Am I crazy? Is this possible?

SSL certificate problem: unable to get local issuer certificate with gdal and curl

$
0
0
* Connected to ascendxyzdatastagingweu.blob.core.windows.net (168.61.57.78) port 443 (#0)
* libcurl is now using a weak random seed!
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0

I got the above eror with vsicurl and gdal and was not able to find any solution on google.

What is the tasks to enable gdal to use vsicurl with https?

Can JPEGs have overviews?

$
0
0

I was a little surprised to see the output of a .jpg file when gdalinfo said it had overviews.

Can jpegs really have overviews or what does this mean? Can they be removed to reduce file size?

Image Structure Metadata:
  COMPRESSION=JPEG
  INTERLEAVE=PIXEL
  SOURCE_COLOR_SPACE=YCbCr
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 4912.0)
Upper Right ( 7360.0,    0.0)
Lower Right ( 7360.0, 4912.0)
Center      ( 3680.0, 2456.0)
Band 1 Block=7360x1 Type=Byte, ColorInterp=Red
  Overviews: 3680x2456, 1840x1228, 920x614
  Image Structure Metadata:
    COMPRESSION=JPEG
Band 2 Block=7360x1 Type=Byte, ColorInterp=Green
  Overviews: 3680x2456, 1840x1228, 920x614
  Image Structure Metadata:
    COMPRESSION=JPEG
Band 3 Block=7360x1 Type=Byte, ColorInterp=Blue
  Overviews: 3680x2456, 1840x1228, 920x614
  Image Structure Metadata:
    COMPRESSION=JPEG
Viewing all 397 articles
Browse latest View live