mapnik / python-mapnik

Python bindings for mapnik
GNU Lesser General Public License v2.1
157 stars 91 forks source link

Error loading map SRID on 'mapnik.load_map()' function #196

Closed mondeja closed 5 years ago

mondeja commented 5 years ago

I'm a layer uploaded to PostGIS with ogr2ogr from a CSV file. The command that does that is:

/usr/bin/ogr2ogr -f "PostgreSQL" PG:"dbname=<db_name> host=localhost user=admin password=<password>" <path/to/layer/file.csv> -nln mataro.masa -lco GEOMETRY_NAME=the_geom -lco GEOM_TYPE="geometry" -nlt PROMOTE_TO_MULTI -append

When I try to create a map from a XML file loading this layer i get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/mondeja/agislm/api/views/service.py", line 251, in service_download_map_view
    bbox)
  File "/home/mondeja/agislm/ageocore/mapnik/image.py", line 60, in generate_map_image
    mapnik.load_map(m, mapfile)
RuntimeError: Postgis Plugin: ERROR:  no existe la función st_srid(character varying)
LINE 1: SELECT ST_SRID("the_geom") AS srid FROM "mataro"."masa" WHER...
               ^
HINT:  Ninguna función coincide en el nombre y tipos de argumentos. Puede ser necesario agregar conversión explícita de tipos.
in executeQuery Full sql was: 'SELECT ST_SRID("the_geom") AS srid FROM "mataro"."masa" WHERE "the_geom" IS NOT NULL LIMIT 1'
  encountered during parsing of layer 'urba_masa' in Layer of '<path/to/style/file.xml>'

If I load the layer from another format like GeoJSON o Shapefile works properly.

I've tryed executing SELECT ST_SRID("the_geom") AS srid FROM "mataro"."masa"; and I get tthe same error, but if I cast the geometry column to geometry type executing SELECT ST_SRID("the_geom"::geometry) AS srid FROM "mataro"."masa"; it works.

So, It's possible that trying to get SRID casting to geometry type in mapnik.load_map() it this error can be solved, or I'm missing something? Thanks for this library.

PD:

>>> mapnik.mapnik_version()
300100

$ /usr/bin/ogr2ogr --version
GDAL 2.3.1, released 2018/06/22

$ geos-config --version
3.7.0
mondeja commented 5 years ago

Yes:

admin_6c82896a=# \dx;
                                       Installed Extensions
      Name      | Version |  Schema   |                             Description                             
------------------+---------+------------+---------------------------------------------------------------------
 plpgsql          | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis          | 2.4.4   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_topology | 2.4.4   | topology   | PostGIS topology spatial types and functions

It's working with layers uploaded on another formats, It's very strange...

talaj commented 5 years ago

ERROR: no existe la función st_srid(character varying)

For some reason, the column type seems to be incorrect.

You can try to set the srid on the datasource.

<Datasource>
   <Parameter name="srid">900913</Parameter>
</Datasource>

I'm concerned this is a problem of creator of the table not a problem with Mapnik.

mondeja commented 5 years ago

It's possible so I'm closing this for now. If I found something related to I will reopen this issue. Thanks!