2

I have a table in which I store a geometry (point, polygon ect). I want to wrote a python program that "draw" those geometry.

I tried to use pgsql2shp and then gdal_rasterize, but the fact that I have mixed geometry types prevent me to progress any further. And when I try with only one geometry, gdal_raserize raise this error :

Attempt to create 0x0 datasete is illegal, size must be larger than zeo.

Those are the command I run :

pgsql2shp -f shapefile.shp -h localhost -u jenkins -P jenkins -p 5432 video "SELECT geom FROM state WHERE name LIKE \'A%\'"
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 -l shapefile shapefile.shp work.tif

The main objective, is to draw those geometry on a map.

8
  • did you tried to split up the different geometry typs in different tables? in addition did the creation of the shapefile worked?
    – LaughU
    May 23 '17 at 13:47
  • The creation of the shapefile seems to work. But I get this warning : Cannot determine spatial reference. No prj file will be generated. Excuse me, I am a beginner with geographical data manipulation.
    – Asew
    May 23 '17 at 13:56
  • my guess is that your shapefile is already emptyand therefor the rasterisation fails. you could have a look at the shapefile using QGIS
    – LaughU
    May 23 '17 at 14:03
  • Drawing vector data on a map is fine... you probably don't need to rasterize it. Quite a lot of GIS will let you display the data directly from the postGIS DB. (and from there you can easily export the data to whatever format you want)
    – JGH
    May 23 '17 at 14:33
  • 1
    Also you should now change your DB password. It is a good idea to never write it on a public website (or any website)
    – JGH
    May 23 '17 at 14:33
4

It looks like you've just solved your problem with QGIS, but for the record...

Does your source geometry in PostGIS have an SRID set? If not, this may be why you're not getting a prj file.

To check:

select * from geometry_columns where f_table_name = 'state';

A result of 0 (or -1 for older PostGIS versions) indicates no srid has been set.

Instead of creating an intermediate shp file, you can extract the data for gdal_rasterize straight from Postgresql/PostGIS.

 gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 \
 -l state -where "name LIKE 'A%'" \
 PG:"host=localhost user=jenkins password=jenkins dbname=video" work.tif

If you don't fix the srid in Postgresql, you can always supply it as a switch to gdal_rasterize: -a_srs

If you're not sure what srid your target tif file is in you can use gdalinfo on it.

Also wrt the multiple geometry types: With shp files, you need to create a separate shp file for each but if you use Postgresql as your source, gdal_rasterize can handle multiple geometry types in one go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.