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

GDAL2Tiles: MapTiles from BSB/KAP are Switched

$
0
0

As an example I have a BSB file from NOAA which is a navigational map. The map has a SRS of WGS84 and a Mercator projection.

I initially translate the file from BSB format to GTiff format using the following command:

gdal_translate -of GTiff 18554_1.kap noaa.tif

I can view this GTiff file using Paint Shop Pro quite fine. I then translate the file from GTiff format to VRT format using the following command:

gdal_translate -of vrt –expand rgba noaa.tif noaa.vrt

I then try to generate a tile matrix set using the following command:

gdal2tiles.py noaa.vrt tiles_folder

Where the map tiles are located in tiles_folder. If I try to open the openmaps.html or google.html, the map zoom in and out looks good. However, on tiles generator like MBTiles, I see tiles swap. See the image below. I am pulling my hair off to get the tiles to line up. I am guessing it is projection error. I am not understanding those projection types. It would great someone can explain it while finding the error. I am planning to use on a tiling airplane maps/charts app like this. By the way, on GDAL how do I specify the BSB (reference) file that is associated with KAP (data) file? I have seen cases where only one BSB file referred by multiple KAP files.

Gdal2tiles.py Tile Image Swaped


Subsetting geotiff with python

$
0
0

I’m sub-setting a geotiff with the gdal python binding and numpy. Essentially, i am providing a central location (coordinates of a flux tower) from which i produce a subsetted image. I then want to write this to a new geotiff. However, my current code does not correctly geocode. I’m having a hard digesting the rather sparse and confusing gdal documentation and so would love for some help. I have read that this might be possible with a gdal_translate.py or a VRT but can not figure out any more from the docs.

So, load the geotiff in question and produce the subset:

datafile = gdal.Open("%s" % filenames_matched[site][filen] )
data = datafile.ReadAsArray()
info = datafile.GetGeoTransform()       
# GDAL provides the top-left coordinate (lat, lon)
#Site_lon and site_lat are the coordinates for the fluxtower site.
# Produce a relative coordinate for the fluxtower (eg relative to gdal ul(lat,lon))
lon_rel = site_lon - info[0]
lat_rel = site_lat - info[3]

#Get pixel size (resolution)
res_we = abs(info[1])
res_ns = abs(info[5])   

#Now convert the relative position from degrees to pixels..
pixel_lon = float ( lon_rel) / res_we
pixel_lat = float ( lat_rel ) / res_ns

# Will, of course, have to round this to the nearest whole pixel...
pixel_lon = round( pixel_lon )
pixel_lat = round( pixel_lat )

# Now need to outline the actual buffer of 24 on each side...
buffer_lon_east = pixel_lon + 24.5
buffer_lon_west = pixel_lon - 24.5
buffer_lat_north = pixel_lat + 24.5
buffer_lat_south = pixel_lat - 24.5

#Produce subset array
subset = data[buffer_lon_west:buffer_lon_east,buffer_lat_south:buffer_lat_north]

And then save the new subsetted geotiff:

Nx, Ny = subset.shape
driver = gdal.GetDriverByName("GTiff")

projection = datafile.GetProjection()    # Same projection as input (WGS84)
ds = driver.Create("%s" % composited_filename, Nx, Ny, 1, gdal.GDT_Float32)
ds.SetProjection(projection)


# Where I imagine the problem is:
# Sets new coordinates from derived ul lat, lon for the subset 
ds.SetGeoTransform([info[0] + lon_rel, info[1], info[2], info[3] + lat_rel, info[4], info[5])



ds.GetRasterBand(1).WriteArray(subset)
ds = None

Python GDAL/OGR: retrieved feature is NoneType

$
0
0

I’m doing some scripts in Python to deal with shapefiles, and I have an issue I don’t understand. I’m looping over a shapefile, and I want to retrieve the geometry of each feature, but very often I get an error saying:

    pointGeo = pointFeat.GetGeometryRef()
AttributeError: 'NoneType' object has no attribute 'GetGeometryRef'

Here’s the way I did it:

        for j in range(pointsLayer.GetFeatureCount()):
                pointFeat = pointsLayer.GetNextFeature()
                pointGeo = pointFeat.GetGeometryRef()
                if pointGeo.Within(whatever):
                    ...

I don’t think my shapefile is corrupted or damaged, as I tried with several… and I often get this error, but for some features I don’t get it.
Any idea how to solve this?

Thanks

ogr2ogr coverting DXF to shapefile, why am I losing part of the feature?

$
0
0

I’m starting to mess around with some of the GDAL toolsets, specifically the ogr2ogr.

I’m working with converting a 2000 ACSII DXF file to shapefiles depending on geometry.

Everything seems to work fine, but I’m not getting the complete feature.

Here’s an example of my command:

ogr2ogr -where "OGR_GEOMETRY='LINESTRING' AND LAYER='E-TRANSFORMER'" -f "ESRI Shapefile" transformers.shp System_Map.dxf

Now this does create a polyline shapefile with a good amount of data, but I’m losing a key part I need, here’s an example of what I need:

enter image description here

The problem is that the conversion is only giving me the line up to the circle.

Each pie of the circle is its own feature and the line is its own feature. So in this picture there are 4 separate features, but they are all part of the E-TRANSFORMER layer.

Can you think of a reason I am only getting the line leading up to the circle and not the circle too?

FME converts it fine, but I’d rather use GDAL if I could.

Thanks for any help.

setup Mapserver WMS from tile files

$
0
0

I’m totally new to Mapserver and I’ve been banging my head trying to figure out how to mount a WMS server that will seed images of a small geographical area to a OpenLayers HTML page.

I already installed Mapserver on windows (MS4W) and “mapserver -v” shows: ‘SUPPORTS=WMS_SERVER’ so that’s done.

Then I used JTileDownloader to get the tiles from the area I’m interested in. I ended up with folders “13″ and “14″ (guess that the zoom level) full of *.png file inside the folder c:TMPMyZone

The next steps seems to be to create an index file from the tiles with gdaltindex witch I manage to install, but I have no idea how to use.

While on the c:TMPMyZone folder I tried:

gdaltindex PR1314.shp

gdaltindex PR1314.shp *.png

gdaltindex PR1314.shp 13*.png

But none of them worked so I don’t kwon what to do, I read a lot articles in Mapserver wiki how-to’s, but the amount of info is overwhelming and I don’t understand half of what I’m reading.

So to recap, I just need a WMS that will seed the tiles I already downloaded. What should I do next?

Thanks.-

gdal_merge.py with single band raster

$
0
0

I’m trying to mosaic the True Marble world imagery 250M geotiffs using gdal_merge.py though one of them doesn’t have RGB bands like the rest and gdal_merge fails (same number of bands is listed as a requirement in it’s documentation). This is the error I get:

python.exe : ERROR 5: TrueMarble.250m.21600x21600.B4.tif: GDALDataset::GetRasterBand(2) - Illegal band #

This is the tile causing the issue: TrueMarble.250m. 21600x21600.B4

Should I use a different mosaic tool or should I try to coerce the tile into the format gdal_merge requires somehow?

Why is GDAL ECW compression much poorer than ECW compression from ERDAS

$
0
0

We use ECW compressor shipped with ERDAS Imagine to export Orthoimagery for our different departments. Because we are facing problems with the Imagine license server, we had to choose GDAL (built with ECW SDK) as a fallback solution. Because the Orthotiles are all approximately 100MB large, thats possible.

As a compression ratio we use 1:20. With ERDAS ECW compressor (it does not matter if we use the licensed one or the free edition from some years ago) the images are all compressed to approximately 4 to 6 MB each.

With GDAL and the same compression ratio, the images got 10 to 20 (!) MB each. ALso some of the files cannot be opened afterwards. Also when I increase the compression ratio (to 1:30 for example) the imagefiles get smaller but face a lack of imagequality very quickly.

Why is GDALs compression significantly more worse than ECW Compressor, when they are both based on the same libraries from the ECW SDK?

Is it because GDALs implementation is so buggy or because ERDAS is keeping its Aces on their sleeve?

EDIT: Yeah, I know that this is truly a naive question ;)

GDAL Utilties – Multiple Bands with Different Output Types

$
0
0

I have a raster dataset with 5 bands. 4 of the bands are 8bit unsigned and the 5th band is 32bit floating point. I need to clip the dataset into tiles using GDAL (I’m using gdalwarp with a cutline from a tile index shapefile).

I typically use gdalwarp -ot BYTE... to specify the output type, but in this case not all bands are the same. Is it possible to specify multiple output types? For instance, could I do gdalwarp -ot BYTE BYTE BYTE BYTE FLOAT32...?


Where can I find a python GDAL 1.8.0 package?

How to check are there any OGRGeometry (polygons) within an OGRGeometry (polygon) ?

$
0
0

Please see my image:

Multipolygon

I used the below statements to get Geometry:

OGRGeometry *poGeometry;

poGeometry = poFeature->GetGeometryRef();

Do you know how to check whether the Polygon 1 (geometry) is empty (or include a small polygon) or not ?

If it is possible, how to get or identify the polygon 2 ?

Thanks and regards,

Tai

Can I append to different tables using ogr2ogr?

$
0
0

I have been through many related questions and links but I am still confused as to how/if this is achievable. So, I have defined tables in my postgis database and I would like my ogr2ogr commnand to append to these existing tables rather than create its own – using GML files that I have.

I have tried using -nln and -sql but I had no success. The -nln option seems useful when importing a shapefile which usually contains one type of geometry thus needing to specify one table only. But what happens when need to specify 11 tables?

Finally, I found some links to use python with ogr library. I have not found good documentation with examples though…

Any suggestions? Thanks in advance!

Kind regards,
A

processing MODIS hdf files with gdal

$
0
0

I’m trying to open an MODIS file (hdf format) with gdal in a python script under windows OS. I use the HDF4 driver, as read at http://www.gdal.org/frmt_hdf4.html.
But when I run it I got this error message:

ERROR 4: `MOD10A1.A2000064.h12v04.005.2007164045648.hdf' not recognised as a supported file format. 

I have tried with the gdal.ALLRegister() statement with the same result. My goal is to obtain the properties of the image using GeoTransform, RasterXSize, etc. and reproject it afterward. If you could provide me with any help it would be much appreciated.

ps. I know I can use the Modis Reprojection Tool (MRT) but I need it to be included in my script as it will iterate over a folder containing a lot of images.

thanks

Problem installing GDAL and fiona module in arcmap10?

$
0
0

I am getting message like this

Traceback (most recent call last):
File “”, line 1, in
File “C:Python26ArcGIS10.0libsite-packagesgdal.py”, line 2, in
from osgeo.gdal import deprecation_warn
File “C:Python26ArcGIS10.0libsite-packagesosgeo__init__.py”, line 21, in
_gdal = swig_import_helper()
File “C:Python26ArcGIS10.0libsite-packagesosgeo__init__.py”, line 17, in swig_import_helper
_mod = imp.load_module(‘_gdal’, fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.

Completely new to GDAL: please help me with the best way to study it

$
0
0

This is the first time that I post here so pardon me for asking such a beginner question.
I’m completely new to GDAL and I’m going to use it to work with satellite images, DEMs, etc.
I have some experience working with Visual C++ and the OpenCV library. And in fact my goal is to combine OpenCV, GDAL and OpenGL for developing software for remote-sensing purposes. The programming language will be Visual C++.

My problem is that in searching the net, I couldn’t find a good book for learning GDAL and in fact most of the open source codes found in the Net are written in the Python language but I’m not familiar with this language and I don’t want to get familiar. Surely I know that the best language for programming with GDAL is Python but the rules of the company where I work force me to use Visual C++.

So with the conditions mentioned above, what do you suggest as the best way to study GDAL?

The first piece of program that I want to write would be:

  1. Read a satellite image file with the help of the GDAL library.
  2. Extract image’s header information.
  3. Write a program to apply a Gaussian filter on the image that was read in step 1.
  4. Convert the image read in step 1 to an image of the OpenCV family to do some other processing.

How to install Shapely, but got stuck into Python language

$
0
0

I have a MAC OSX 10.7.5 and am trying to learn how to use QGIS.
Following a couple of tutorials I came to know I have to install shapely.

I followed the instructions by the multi-cited http://tumblr.pauladamsmith.com, but I am afraid I did not understand neither how to start the installation.

I downloaded all the required files (i.e. GDAL 1.10 and its python package but did not move them in any particular directory – i.e. the complete GDAL framework seems to be installed into Library and the GDAL python package is still in the Download folder).

I did the following, thanks to the instructions of the link above:

MacBook-Pro-di-myname:Downloads myname$ cd /Users/myname/Downloads/GDAL-1.9.1 
MacBook-Pro-di-myname:GDAL-1.9.1 myname$ CFLAGS=`/Library/Frameworks/GDAL.framework/Versions/1.10/Programs/gdal-config --cflags`
MacBook-Pro-di-myname:GDAL-1.9.1 myname$ LDFLAGS=`/Library/Frameworks/GDAL.framework/Versions/1.10/Programs/gdal-config --libs` python setup.py install

but then that’s what I get:

running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-3861.write-test'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

/Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

http://peak.telecommunity.com/EasyInstall.html

Please make the appropriate changes for your system and try again.

Where is this error coming from? What I am getting wrong? Since this error impedes me to continue I cannot follow the other instructions at the link above, so I am pretty stuck with my work and cannot continue.

I will appreciate any type of help: I am totally ignorant on Python language and programming as a whole, indeed it was an unexpected problem during my QGIS learning.

Thanks a lot
Fra


Is there a way to tell the supported input formats of libmap.dll without the associated .exe?

$
0
0

I have only compiled Mapscript_csharp and supporting dlls used in a .NET application – not the executables. Is there a way to tell what input / output formats are supported by these dlls?

gdal_grid unable to get nodata outside of original data area

$
0
0

I have a vector based csv file that I want to convert into a grid using gdal_grid, but I want to force null data values strictly around the area where there is data. I can get gdal_grid to work but it is always just smoothing the whole grid rather than giving me null data outside of the shape. Can someone tell me what settings to use to make sure that I get null data inside the grid where there is no data within the original csv.

Many thanks

How to read csv with WKT geometry in Arcmap?

$
0
0

I have found several parcels I need on a county map viewer. However, the only option to download any of the data is found on a click context menu to “Copy selection as csv” which gives me this:

HGID,ShapeWKT,parcelnumber,locationstreet,owner2,totalassd,parcelid,sec,ownerzip1,ownermailing1,rge,ownerstate,owner1,ownercity,formattedparcel,twp
"13514","POLYGON((825759.0653999997 326186.8526000008,825590.3153999997 326176.4357999992,825572.2887000003 326356.2666999996,825741.2658000002 326367.40330000035,825759.0653999997 326186.8526000008))","1406130003000009000","1470  HIGHWAY M","","9810","10682","13","63902","P O BOX 1021"," 5","MO","RHODES FREDERICK & PATRICIA","POPLAR BLUFF","14-06-13.0-003-000-009.000","24"
"13512","POLYGON((825759.0653999997 326186.8526000008,825770.4408999998 326065.06709999964,825776.7737999997 325997.26920000085,825727.1403000002 325988.53079999983,825720.1957999999 325559.36419999966,825716.0288000003 325041.31090000086,825380.9403999997 325018.1026000008,825384.6557 325291.9681000002,825387.7232999997 325518.09530000016,825390.7329000003 325739.9436000008,825393.6021999997 325951.46199999936,825395.5236999998 326093.1026000008,825399.5045999996 326344.8791000005,825572.2887000003 326356.2666999996,825590.3153999997 326176.4357999992,825759.0653999997 326186.8526000008))","1406130003000010000","M HWY","","10530","10683","13","63901","1563 M HWY"," 5","MO","MORGAN SHERMAN F & MARY I","POPLAR BLUFF","14-06-13.0-003-000-010.000","24"

I pasted this into a text editor, but I am unfamilliar with the file format. It is not a point based csv that could be added to ArcMap using Display XY data. It looks like it may be some type of OGR file like this (http://www.gdal.org/ogr/drv_csv.html).

Is there a way to convert the csv file to a format readable in ArcMap rather than using GDAL?

It looks like I may be able to creat an associated .vrt file, but I am not sure where I could go from here as far as getting the data into ArcMap. VRT might look something like this something like this:

 <OGRVRTDataSource>
    <OGRVRTLayer name="test">
        <SrcDataSource>parcels.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="Longitude" y="Latitude"/>
    </OGRVRTLayer>
</OGRVRTDataSource> 

Why does ogr2ogr SHP import error out trying to create a database?

$
0
0

All,

Can anyone tell me what the error is with OGR2OGR when trying to import a .SHP into MSSQLSPATIAL?

ERROR 1: MSSQL Spatial driver doesn't currently support database creation.
Please create database with the Microsoft SQL Server Client Tools.
MSSQLSpatial driver failed to create MSSQL:server=[][];database
=[];uid=[];pwd:[]

The import statement I’m using is this:

ogr2ogr -f MSSQLSpatial "MSSQL:server=[][];database=[];uid=[];pwd:[]" C:[path to file]police_districts_2877.shp -a_srs EPSG:2877 -lco "GEOM_TYPE=geometry" -lco "GEOM_NAME=geom" -nln "CCD_PoliceDistricts" -progress

As you can see, I’m not trying to create a database, and there is one already created. as per the ‘creation issue’ cited here: http://www.gdal.org/ogr/drv_mssqlspatial.html

I have followed several posts, including this:
Shapefile to MSSQL with ogr2ogr fails to make connection, to no avail…

EDIT: I’m also getting a connection error, but I can’t see why…I think my syntax is correct:

ERROR 1: Unable to initialize connection to the server for MSSQL:server=[][];database=[];uid=[];pwd:[],[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '[username]'.

Thanks!

-m

QGIS 1.8.0 on Linux treats NetCDF 4 as HDF5

$
0
0

I’ve been generating some large (28800×13920) grids of BYTE data representing the NALCMS2005 North American Land Cover dataset (original 250m projected data resampled to a WGS84 grid at 15 arc sec). I store the grid as a NetCDF 4 file with GZIP compression, using gzip level 6 and CF conventions; i.e. I use a “crs” variable to define the coordinate reference system, “lat” and “lon” dimensions and coordinate variables to define the geodetic latitude and longitude axes, and “lat_bounds” and “lon_bounds” variables to define the bounds of each row/column of the grid.

When I select one of these files with qgis-1.8.0-9_0.el6.x86_64 on a CentOS system or with qgis-1.8.0-6.fc16.i686 on a Fedora Core 16 system (these are my two Linux options right now), the “Select raster layers to add…” dialog that lists the layers found in the file displays them as

HDF5:”NA_LandCover_2005_WGS84_500m.nc”://Data

QGIS is able to load the data and display it, but the coordinate reference system and grid geometry are completely ignored. I realize that NetCDF4 files are technically also HDF5 files, but read on.

When I select one of the same files with QGIS on a Mac (Mountain Lion 10.8.4), the “Select raster layers to add…” dialog show the layers in the file as

NETCDF:”NA_LandCover_2005_WGS84_500m.nc”://Data

and successfully recognizes the CRS in the file. Unfortunately, this solution is not doing a lot for me because reading and displaying the data on this system takes about 30 minutes, and good luck changing anything or doing any navigation.

So… if I do “gdalinfo –formats | grep -i df” on the different systems I get exactly the same result:

GMT (rw): GMT NetCDF Grid Format
netCDF (rw+): Network Common Data Format
HDF4 (ro): Hierarchical Data Format Release 4
HDF4Image (rw+): HDF4 Dataset
NDF (rov): NLAPS Data Format
HDF5 (ro): Hierarchical Data Format Release 5
HDF5Image (ro): HDF5 Dataset

“gdalinfo –version” on the three systems:

  • Mac: GDAL 1.9.1, released 2012/05/15
  • FC16: GDAL 1.7.3, released 2010/11/10
  • CentOS 6.3: GDAL 1.8.1, released 2011/07/09

Maybe those older GDAL libraries on the Linux systems are the problem and I just need to build QGIS from source using GDAL 1.9 on one of the Linux machines.

Viewing all 397 articles
Browse latest View live