[Gdal-dev] Read/Write Oracle Spatial

Frank Warmerdam warmerdam at pobox.com
Wed Oct 26 13:01:57 EDT 2005


On 10/26/05, Hallgren Johan E <jhhal at wmdata.com> wrote:
> OGR.Driver d = OGR.ogr.GetDriverByName("OCI");
> OGR.DataSource ds = d.Open(@"OCI:wmgis/wmgis01 at WMSI1394", 1);
>
> GDAL.gdal.SetConfigOption("OGR_FID","OBJECTID");

Johan,

You need to call SetConfigOption() before opening the datasource
as it alters the decisions made as the layers are scanned during
the open.

> I tried to do add a column OGR_FID (primary key) to the table but in that case it failed on the SetFeature with no meaningful error message. Now the actual record was gone so my guess is that the function removes the record and when adding a new it fails (can it be something with the OGR_FID not being properly updated?).

SetFeature does indeed operate by deleting the existing row and re-creating
it.   You could do a StartTransaction() and Commit() or Rollback() after
the SetFeature() if you want better error handling.  It really ought to do
this internally if there is no active transaction.

> Finally, is it the right way to use SetFeature when updating a record?
>
> I hope you have time to answer my questions.

I think you are doing things right, and I am not sure why it isn't
working; however, I don't think SetFeature() is used often.  I see
it is not used in the ogr_oci.py test script for the OCI provider.  It
may just be broken.

Unfortunately, while I have time to answer this question, I don't
have time to reboot into win32, and fiddle around to see what is
going wrong today.  You might want to file a bug report.

For now it is hard to say if you are encountering some limitation
of the c# bindings or ogr.

... one extra review of your code ...

Actually, now I see you are doing things in a transaction, but
committing it even if the SetFeature() fails.

Also, more seriously, I see you are fetching a reference to the
feature geometry modifying it and then calling SetGeometryDirectly().
The problem with this is that GetGeometryRef() returns a pointer to
the internal feature geometry.  So you are modifying it directly on
the feature, and then when you do the SetGeometryDirectly() it
will delete the old geometry and try to set the new one.  But the
new one is really the old one, now deleted.  So you should skip
the SetGeometryDirectly() step ... or .. clone the result that comes
back from GetGeometryRef().

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list