Skip to content

How to have vector datasets supporting long text fields in GeoNode

Ben Lewis edited this page May 15, 2018 · 7 revisions

When uploading a shapefile to GeoNode, the shapefile is internally exported to a PostGIS spatial database, and text field length in PostGIS will be converted to the same length as it was in the original uploaded shapefile, which can't exceed 255 characters.

How is it possible to have vector datasets which support long text fields in GeoNode?

There are a few possible workflows:

Create layers using the "Create Layer" tool

All of the string fields created using this tool will have text which can contain any number of characters.

Alter fields after uploading a shapefile

When uploading a shapefile, text fields length in PostGIS will be the same length as it is in the shapefile, 255 characters. It is possible however, using the GeoNode administrator, to make any text field of the uploaded shapefile support a larger number of characters.

Let's suppose a shapefile named "shape_desc" has been uploaded to GeoNode. Here is how a GeoNode administrator can alter a field of the shapefile (in the sample code, named "descriptio") to support a virtually unlimited number of characters in PostgreSQL/PostGIS by using psql:

ALTER TABLE shape_desc
ALTER COLUMN descriptio TYPE character varying;

After this action users will be able to add any quantity of text to the "descriptio" field for the features of the vector layer.

Import an existing layer in PostgreSQL/PostGIS and register it for GeoNode with the updatelayers command

This is a workflow which can be used by the GeoNode administrator/s.

There are a number of formats that can be used to store text fields which contains more than the 255 characters (unlike the shapefile format, which only supports up to 255 characters).

For example using QGIS it is possible to create a layer in the spatialite format, which supports text fields with unlimited characters length and with the necessary encoding. It is then possible to import the layer to the GeoNode PostGIS/PostgreSQL database and register it in GeoNode using the updatelayers command.

Here is a full sample workflow:

  • create a spatialite database in QGIS. Name the database "camp_test"
  • create a layer in spatialite format using QGIS. Name the layer "layer_test". Add the needed fields, including the ones which need to support unlimited text characters
  • use QGIS to edit the layer and its text fields
  • import the spatialite layer in the PostgreSQL/PostGIS GeoNode database using ogr2ogr (or QGIS itself). If using ogr2ogr:
ogr2ogr -f PostgreSQL PG:"dbname='wmdata' host='localhost' port='5432' user='myuser' password='mypassowrd'" camp_test.sqlite
  • register the layer in GeoNode using the updatelayers Django GeoNode command:
python manage.py updatelayers -f layer_test

Now layer layer_test will be available in GeoNode.