Opened 12 years ago

Closed 5 years ago

#4759 closed enhancement (wontfix)

CouchDB/SHP driver - SHP with NULL values handling and ability to specify _id field

Reported by: shr3k Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: default Version: 1.9.1
Severity: normal Keywords: SHP, CouchDB, NULL handling
Cc:

Description

It would be great to be able to specify whether to NULL values ​​in SHP files fields should create an empty attributes in CouchDB/GML and also be able to generate CouchDB _id attribute from the SHP/GML fields.

Change History (7)

comment:1 by Even Rouault, 12 years ago

Please avoid mixing different requests/issues in the same ticket.

1) About "to be able to specify whether to NULL values ​​in SHP files fields should create an empty attributes in CouchDB/GML" : what do you mean by an empty attribute in couchDB / GML ?

From my analysis, the current situation is that :

  • for CouchDB, we will write "attribute_name : null" in the JSon content
  • for GML, we will omit the XML element

So, for strings, I would understand your request as writing the empty string "" as the value, is that right (but what if the attribute type is not a string?) ? Could you explain a bit more the rationale for that ?

2) About "be able to generate CouchDB _id attribute from the SHP/GML fields", there's a COUCHDB_PRESERVE_ID_ON_INSERT configuration option (undocumented, perhaps it should be indeed) that might help you do what you want. If it is set to YES, then it will use the content of the "_id" field of the feature to be created if it is defined (the default behaviour is to increment a serial number).

You could try something like :

ogr2ogr -f CouchDB CouchDB:xxxxxx yourshape.shp -sql "select field1, field2, ..., field_id as _id from yourshape" --config COUCHDB_PRESERVE_ID_ON_INSERT YES

comment:2 by shr3k, 12 years ago

Mixing issues - okay, thank you for notice.

1) If I upload a SHP with NULL values in TEXT DBF fields, created CouchDB JSON documents have this fields (properties) null. Unfortunately, this isn't incompatible with GeoExt.Popup with Ext.grid.PropertyGrid sourcing from GeoJSON properties - PropertyGrid doesn't show these null properties at all and I can't update them & POST back to CouchDB. To bypass this, I must convert the SHP to GML first, use sed to replace all <ogr:*></ogr:*> attributes with <ogr:*> </ogr:*> and then upload this modified GML to CouchDB.

2) COUCHDB_PRESERVE_ID_ON_INSERT, that's exactly what I needed, thanks. :-)

comment:3 by Even Rouault, 12 years ago

1) I think that would be worth a ticket for GeoExt, right ? What is surprising me is that when you convert the shape to GML, you get <ogr:something></ogr:something>. I've checked the GML driver and if a field isn't set, it doesn't write anything. Perhaps your DBF doesn't contain NULL values but an empty string : if you run ogrinfo on the shape, does it report "a_field = (null)" or "a_field = " ?

comment:4 by shr3k, 12 years ago

This is however Ext JS feature since Ext.grid.PropertyGrid was made (and it comes from logic as PropertyGrid doesn't recognize whether should handle these null properties as string or as a number).

And yes, you're right, to become GML with empty fields from SHP with NULL I'm using Quantum GIS. With ogr2ogr it doesn't work. Or to convert it with ogr2ogr one must replace NULL values with something like '@@@' and then replace these @@@'s with space with sed.

comment:5 by Even Rouault, 12 years ago

Ok, I understand your use case better. However replacing NULL with empty string only makes sense for string fields. What to do if a numeric field has an empty value ? : replacing it with empty string would not be appropriate.

Not sure if this kind of hack is appropriate, and where (ogr2ogr level or CouchDB driver) it should be made. It could be something generic, thus in ogr2ogr, a -nullasempty option ?, but we have already (too) many options in ogr2ogr, a lot being my own fault :-)

For your needs, you could customize the python version of ogr2ogr ( http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/samples/ogr2ogr.py ) to replace null values by empty strings before CreateFeature()

comment:6 by shr3k, 12 years ago

I thought numeric fields (INT or FLOAT) should become 0. Anyway it's up to you, I'd suggest some CouchDB/GeoJSON driver specific -lco as NULLASEMPTY and NULLASZERO, because this problem rises up mainly from JSON's nature, but as I wrote I can survive without.

Besides of described SNULL handling would be great to achieve same NULL behaviour with SHP to GML conversion as qgis has.

comment:7 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.