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

Issues installing GDAL with PostgreSQL

$
0
0

I’m trying to install gdal-1.11.0 on CentOS 6 machine.
Following the instructions, this is my config

./configure --prefix /usr/local  --with-fgdb=/usr/local/FileGDB_API --with-pg=/usr/pgsql-9.3/bin/pg_config

As the configure process runs, I see this in the output:

checking for PostgreSQL... yes

However, at the end of the configure output, I see this:

PostgreSQL support:        no

PostgreSQL 9.3 is up and running with postgis on it, the path to pg_config is correct. I know the configure is reading it, because if I put a bad path in –with-pg, it complains…
I had prior installs of earlier versions of GDAL, and GDAL 1.11 without postgreSQL before I realized that I need to build it with PostgreSQL support.
What am I missing?


GDAL C++ API: How to create PNG or JPEG from scratch

$
0
0

I’m new to GIS and GDAL. My question probably is very basic, but I couldn’t find answer. May be I don’t understand GDAL ideology.

I need to create raster images from scratch, for example, JPEG or PNG. Their drivers don’t support Create function – only CreateCopy. What is the common technique of new files creation in this case?

In principle, I can try to create Tiff because its driver suports Create(). Next, I can use CreateCopy() for PNG or JPEG using this Tiff. But such method looks indirect and unnatural for me. Also I suppose that this procedure can be too memory hungry if rasters are large.

I dealt with some image libraries before, they usually provide direct and simple way of bitmaps creation. Could somebody show me right direction for GDAL?

Thank you in advance,

Alexei

Reprojection error

$
0
0

I have a lidar file (file.las) with the following spatial reference:

Spatial Reference:           
PROJCS["NAD83 / UTM zone 11N",
    GEOGCS["NAD83",
        DATUM["North_American_Datum_1983",
            SPHEROID["GRS 1980",6378137,298.2572221010002,
                AUTHORITY["EPSG","7019"]],
            AUTHORITY["EPSG","6269"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4269"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-117],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","26911"]]

Then I reproject it to WGS84 with las2las:

las2las --a_srs EPSG:26911 --t_srs EPSG:4326 -i file1.las -o output.las

And I get:

Spatial Reference:           
    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"]]

But when I try to revert the transformation: from WGS84 to NAD83/UTM 11N, I get an error:

las2las --a_srs EPSG:4326 --t_srs EPSG:26911 -i output.las -o wgs2utm.las
ERROR 1: latitude or longitude exceeded limits
error: Could not project point for ReprojectionTransform::latitude or longitude exceeded limits0.

Why I got this error, if I am just reversing the transformation (originally from NAD83 to WGS84, and then from WGS84 to NAD83)?.

Using gdal-java of OSGeo4W

$
0
0

I would like to use gdal_polygonize and gdalinfo in java.
This site says: “Note that OSGeo4W includes a gdal-java package and a Java runtime making it fairly easily to build local Java applications using GDAL.” But how?

How to create a mosaic in QGIS with cutline and feathering for Landsat-8 imagery

$
0
0

1 – I have two scenes Landsat-8 RGB 6/5/4 and I need to mosaic them:

Landsat-8 scenes

2- This is my cutline in polygon format that will smooth the overlapping area:

Landsat-8 polygon cutline

3 – So, I need to create a mosaic with feathering like ERDAS or ENVI applications. This is my goal:

Landsat-8 mosaic with cutline and feathering

It’s possible to make this in QGIS, GDAL or another opensource software?

Georeferencing using Liblas error

$
0
0

I am trying to write georeferencing information to a ‘.las’ file using liblas and c++.
Here is my code:

   ofstream ofs;
   ofs.open("test.las", ios::out | ios::binary);
   liblas::Header header;
   liblas::Writer writer(ofs, header);

   liblas::Point point(&header);
   point.SetCoordinates(1.0, 2.0, 3.0);

   writer.WritePoint(point);
   header.SetPointRecordsCount(1);

   liblas::SpatialReference srs;
   srs.SetFromUserInput("EPSG:4326");
   header.SetSRS(srs);
   writer.SetHeader(header);
   writer.WriteHeader();

But, when I check the file using lasinfo tool I get:

 Spatial Reference:           None

If I check proj4, the information is stored, so I don’t know why lasinfo doesn’t print it:

Code  : std::cout << srs.GetProj4() << std::endl;
Output: +proj=longlat +datum=WGS84 +no_defs 

However, when I use lasinfo tool with others las files not written by me I can see the WKT and geotiff output.

What am I doing wrong?

downsample raster map with average algorithm

$
0
0

I need to downsample map to new map with less resolution
NOT for overview BUT to new map file with smaller size

I need to do that with gdal Utils
thanks!

Downsample raster average map with control on the average algorithm

$
0
0

I need to downsample raster average map with control on the average algorithm to 1/4 from original size


How to crop Geotiff image in C++ (GDAL or other possibilities)?

$
0
0

I am developing a code to process a geotiff image. But firsly I need to crop a geotiff image preserving its metadata (projection…) in C++. My idea it’s to provide the corners and the geotiff image to a function inside the code and then it return the subset. I thought about using GDAL but I don´t know if there is any code or function. Anybody know about this? Thanks.

Load the raster image which is in TIF format using QGIS API

$
0
0

I am quite new inthe field of GIS.
I am interested in is to load the raster image which is in TIF format using QGIS API

I have followed the steps given the in the follwing link to load shape file
enter link description here
http://geospatialdesktop.com/2009/02/creating_a_standalone_gis_application_1/ and it works fine

To load the rester image i have followed the steps given int he link
http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html

I have python 2.7.6 ,GDAL 1.10.1 installed with qgis2.0 installed in my system

code snippet

import osgeo.gdal
from  gdalconst import *
from PyQt4.QtCore import QFileInfo,QSettings
from qgis.core import QgsRasterLayer, QgsCoordinateReferenceSystem

file = QFileDialog.getOpenFileName(self, 
    "Open TIF Image", ".", "Tagged image (*.tif)")
fileInfo = QFileInfo(file)    
fileName=fileInfo.fileName()
baseName = fileInfo.baseName()

layer = QgsRasterLayer(fileName, baseName)    

but the image is not loaded and i got the following error in the terminal

ERROR 4: `mypic.tif' does not exist in the file system,
and is not recognised as a supported dataset name.

Layer failed to load!
QObject::connect: Cannot connect (null)::repaintRequested() to QgsMapCanvas::refresh()
QObject::connect: Cannot connect (null)::screenUpdateRequested() to QgsMapCanvas::updateMap()

specifying extent in GDAL's WriteArray

$
0
0

Is it possible to specify the extent when creating an empty raster in GDAL? I looked everywhere, but can’t seem to find anything. The portion of my script where I write the raster would look something like this:

tifpath = "path/to/output/tiff.tif"
drvtif = gdal.GetDriverByName("GTiff")
rast = drvtif.Create(tifpath, Ncolumns, Nrows, Nbands, datatype)
rast.SetProjection(projection) # projection being a variable representing the desired projection
rast.GetRasterBand(1).WriteArray(array)

My array is an array of size Ncolumns x Nrows, filled with 0′s (I want an empty raster). The number of pixels is predetermined, as is the cell size, and by multiplying npixels*cellsize, I’ve determined what my output extents need to be such that each pixel is a whole pixel (i.e. doesn’t get cut off by the extent).

But, I can’t find any options that would allow me to specify the desired extent. Suggestions?

EDIT: It’s also just occurred to me that I don’t see any option to specify cell size. Am I missing something here?

Thanks

Using GDAL to get vertices of a multipolygon

Georeferencing uneven/irregularly gridded rasters

$
0
0

I’m trying to take a set of NetCDFs and turn them into georeferenced datasets using GDAL.

However, the only Geospatial data is a set of 2-D lat/lon arrays. The projection type is not lat/lon. THe arrays give the lat/lon of every individual cell.

I can’t use a geotransform to reference the data because of the irregular gridding.

How can I create a dataset (such as a GeoTiff) that properly references the data? Ideally I would then warp to some even grid.

EDIT: I tried using an even spread of Ground Control Points, but the resulting GeoTiff did not display correctly… Despite giving GCPs up to 90 deg lat, ArcMap claims the GTiff has an extent ending at 70 deg latitude…

EDIT: Thanks to everyone for their help. I was able to solve the issue using gdalwarp -geoloc as suggested. I created 3 VRTs (1 with cell values, 1 with latitude, 1 with longitude), and wrote the lat/lon vrts in a geoarrays in the data vrt metadata. Then using gdalwarp -geoloc worked like a charm.

The issue with extent was unrelated and due simply to the large difference between the original coordinate system and lat/lon. It was solved by explicitely stating the extent instead of having GDAL try to guess what it should be. (i.e. I added -te -180 0 180 90 to the gdalwarp line)

Thanks everyone!

specifying extent in GDAL's WriteArray

$
0
0

Is it possible to specify the extent when creating an empty raster in GDAL? I looked everywhere, but can’t seem to find anything. The portion of my script where I write the raster would look something like this:

tifpath = "path/to/output/tiff.tif"
drvtif = gdal.GetDriverByName("GTiff")
rast = drvtif.Create(tifpath, Ncolumns, Nrows, Nbands, datatype)
rast.SetProjection(projection) # projection being a variable representing the desired projection
rast.GetRasterBand(1).WriteArray(array)

My array is an array of size Ncolumns x Nrows, filled with 0′s (I want an empty raster). The number of pixels is predetermined, as is the cell size, and by multiplying npixels*cellsize, I’ve determined what my output extents need to be such that each pixel is a whole pixel (i.e. doesn’t get cut off by the extent).

But, I can’t find any options that would allow me to specify the desired extent. Suggestions?

EDIT: It’s also just occurred to me that I don’t see any option to specify cell size. Am I missing something here?

Thanks

Can I export overview with gdal?

$
0
0

How can I export overview for example 1/4 from the orginal raster map to a geotiff file using gdal?


Converting in batch into 8 unsigned bit format using GDAL?

$
0
0

Could you please correct my batch command?

I had 100 img images which need to be converted into 8 unsigned bit format for further use in TIMESAT.

mkdir test
for %%f in (*.img) do gdal_translate -of ENVI -scale -1 1 1 255 -a_nodata 0 -co INTERLEAVE=BSQ "%%f" test/%%f.dat

gdal ReadAsArray returning NoneType

$
0
0

I’m trying to read in several rasters as array using gdal in a python script, but I keep getting NoneType returned and can’t figure out why.

The process is this:
1. Use gdalbuildvrt (http://www.gdal.org/gdalbuildvrt.html) to read in several rasters into gdal’s virtual format.
2. Loop through the rasters (aka the layers) of the .vrt, reading them into a temporary array and adding the temp array to the cumulative (or total) array.
3. Write the total array to the raster.

import os
import gdal
from osgeo.gdal import *
import numpy as np
gdal.UseExceptions() 

# intxtlist = a text file with the rasters to be put in the vrt; in this case there are 3 files
VRTstack = '/path/tempVRT.vrt'
os.system('gdalbuildvrt -separate -vrtnodata 0 -input_file_list %s %s' % (intxtlist, VRTstack))

vrtDS = gdal.Open(VRTstack)
Nlayers = vrtDS.RasterCount # Nlayers = 3 because there were 3 input rasters
Nsamp = vrtDS.RasterXSize
Nline = vrtDS.RasterYSize

totalArr = np.zeros((Nline, Nsamp), dtype = 'uint16') # preallocate an array for the final output total
for N in range(0, Nlayers):
    tempArr = vrtDS.GetRasterBand(N+1).ReadAsArray() # tempArray is now Nth tiff of stack as array; N+1 b/c gdal starts at 1
    print type(tempArr)
    totalArr += tempArr  # add the temp array to the final array
## code here to write totalArr as raster

The problem I’m getting is with the second N in the for loop. When N=0, “print type(tempArr)” returns: type ‘numpy.ndarray’, which I would expect. When N=1, however, type(tempArr) returns type ‘NoneType’, which I can’t understand. The entire script then fails at line “totalArr += tempArr” because you can’t add NoneType to a numpy int array.

What’s weird is that no matter how I loop through, the “second” N always fails. For example, “for N in [1, 0, 2]:” returns an array for N=1 and N=2 but returns NoneType when N=0 (even though N=0 didn’t fail when going from 0 to Nlayers (aka 0, 1, 2)) and “for N in [2, 1, 0]:” works for N=2 and N=0 but not N=1.

I’m pretty sure there’s nothing wrong with the vrt itself, as ‘gdalinfo %s’ % VRTstack’ returns accurate information on all three bands.

Also worth mentioning is that this script worked with one set of images (call it S1), but not another (S2). The only real difference between each set is that S1 has a coarser resolution, and its rasters are 32-bit signed type, while S2′s raster type is 8-bit unsigned. I thought that maybe it had something to do with the fact that I was trying to read in unit8 rasters and add it to a uint16, so I tried making totalArray type uint 8 as well, but it still failed. It later occurred to me that this wouldn’t change anything, because tempArr is NoneType before it even gets added to totalArray.

Thanks

UPDATE: When using 5 images instead of just 3, NoneType is always/only returned for the 2nd and 4th N in the loop. That is, when looping through N=0 to N=4, numpy arrays are returned for N=0,2,4, while NoneType is returned for N=1 and N=3. Similarily, when the loop is “for N in [1, 0, 3, 2, 4],” arrays are correctly returned for N=1,3,4 but NoneType is returned for N=0 and N=2. Bizarre.

How to convert SPOT NDVI hdf file to tiff file using gdal_translate command

$
0
0

I have SPOT NDVI images. I want to convert NDVI hdf to tiff. I have used the following code to get the information of hdf file:

gdalinfo 20060501_NDVI.HDF

I get the following output

Driver: HDF4Image/HDF4 Dataset
Files: 20060501_NDVI.HDF
Size is 8849, 5601
Coordinate System is `'
Metadata:
 valid_range=0, 255
Corner Coordinates:
  Upper Left  (    0.0,    0.0)
  Lower Left  (    0.0, 5601.0)
  Upper Right ( 8849.0,    0.0)
  Lower Right ( 8849.0, 5601.0)
  Center      ( 4424.5, 2800.5)
  Band 1 Block=8849x113 Type=Byte, ColorInterp=Gray

As I do not get any information about the SUBDATA SETS in the gdalinfo command I use the following code to convert HDF to TIFF

gdal_translate -of GTiff 'HDF4Image:"20060501_NDVI.HDF":*NDVI'

But I get the output as

FAILURE: No target dataset specified.

As no DATASET is specified, I unable to specify any target dataset. Please let me know how to resolve this. Also I would like to resample the image to 250m resolution by using nearest neighbour (default) method.

ogr2ogr unable to open KML datasource

$
0
0

I downloaded some Wikimapia data using the wikimapia.api. Everything is A-OK since I’ve opened this in Google Earth and everything is in place. However, I need to turn it into a shapefile, or get the data onto QGIS, since there are impt polygons.

Using GDAL Complete for OS X from kyngchaos, I try to run the ogr2ogr command.

Ryans-MacBook-Air:~ Ryan$ ogr2ogr -f “ESRI Shapefile” mountains.shp api.wikimapia.org-4.kml
ERROR 4: Cannot open api.wikimapia.org-4.kml
FAILURE:
Unable to open datasource `api.wikimapia.org-4.kml’ with the following drivers.

etcetc. These are named mountains which I wish to import onto QGIS.

Please help!!

QGIS Polygonize (GDAL) problem – Null value in attribute

$
0
0

Is it possible to use Polygonize in QGIS (GDAL) so that a line shapefile is converted to a polygon shapefile with an attribute(s) in the line file carried into the polygon file. I am trying to build an elevation polygon dataset – I downloaded data from EU-DEM, clipped and merged a few files into a new raster. Then created contours from the new raster. Now I want to create polygons – however the elevation value is not retained in the output polygon shapefile.
I have said yes to the option Keep Table Structure of Line Layer.
THe struture of the polygons are all fine but the value in the elevation attribute is NULL.
One way around of this is to do it for each value of elevation 100, 200….up to the max. Then add an attribute and set it to the correct value – however it would be quicker if Polygonize could do it. Am I missing something here? Is this a bug in Polygonize or was it just not designed to do this? Anyone got any ideas? I am using QGIS 2.4.

Viewing all 397 articles
Browse latest View live