[Gdal-dev] Read/Write Oracle Spatial
Hallgren Johan E
jhhal at wmdata.com
Wed Oct 26 05:07:20 EDT 2005
Thanks Frank for everything!
There is a threshold to use GDAL and MapServer but when passed that test, it´s great tools.
The -1 issue at FID was something I have done wrong. When I tried it today it was other values.
Regarding the c# environment, it works well. Unfortunately I had some problems with the swig thing. When I runned the nmake -f makefile.vc csharp at the swig directory two problems occurred. First there were references used in some dlls that couldn't be resolved.
I changed the following lines in the cshart/makefile.vc (the osr\*.cs was added to all libs):
csc /debug:full /target:library /out:gdal_osr_csharp.dll osr\*.cs
csc /debug:full /target:library /out:gdal_ogr_csharp.dll ogr\*.cs osr\*.cs
csc /debug:full /target:library /out:gdal_ogr_csharp.dll ogr\*.cs osr\*.cs
csc /debug:full /target:library /out:gdal_gdal_csharp.dll gdal\*.cs osr\*.cs
csc /debug:full /target:library /out:gdal_gdalconst_csharp.dll const\*.cs osr\*.cs
I also had to add a
using OSR; to all files that use that library. It will be overwritten when running swig so I had to do the process in two steps (I runned the nmake /f cshart/makefile.vc by my self).
Now to my actual problem:
I wasn't sure how to use the SetConfigOption function. Look below and say if it looks OK.
When I run the following code:
------------------------
OGR.ogr.RegisterAll();
OGR.Driver d = OGR.ogr.GetDriverByName("OCI");
OGR.DataSource ds = d.Open(@"OCI:wmgis/wmgis01 at WMSI1394", 1);
GDAL.gdal.SetConfigOption("OGR_FID","OBJECTID");
OGR.Layer l = ds.GetLayerByName("baggis_lines");
OGR.Feature f = l.GetFeature(74);
Console.WriteLine("FID={0}", f.GetFID());
for (int i = 0; i < l.GetLayerDefn().GetFieldCount(); i++)
Console.WriteLine("{0}=[{1}]", l.GetLayerDefn().GetFieldDefn(i).GetName(), f.GetFieldAsString(i));
OGR.Geometry g = f.GetGeometryRef();
double x = g.GetX(0);
double y = g.GetY(0);
double z = g.GetZ(0);
x += 1.0;
y += 1.0;
Console.WriteLine("x={0} y={1}", x, y);
l.StartTransaction();
g.SetPoint(0, x, y, z);
f.SetGeometryDirectly(g);
f.SetField("TEXT", "OLLE");
l.SetFeature(f);
l.CommitTransaction();
------------------------
I will get the following output:
FID=74
TEXTH=[]
TEXT=[]
OBJECTID=[26]
x=1662872,5 y=6678600
ERROR 1: OGROCITableLayer::SetFeature(74) failed because there is no apparent FID column on table BAGGIS_LINES.
It seams as the SetConfigOption doesn't work as I have used it.
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?).
Finally, is it the right way to use SetFeature when updating a record?
I hope you have time to answer my questions.
Best Regards
Johan
___________________________________
Johan Hallgren
WM-data
Pelle Bergs backe 3
Box 1938, 791 19 Falun
Tel: 023-844 65 (int: +46-2384465)
Mobil: 070-588 44 28 (int: +46-705884428)
johan.e.hallgren at wmdata.com
http://www.wmdata.se
-----Ursprungligt meddelande-----
Från: fwarmerdam at gmail.com [mailto:fwarmerdam at gmail.com] För Frank Warmerdam
Skickat: den 25 oktober 2005 17:13
Till: Hallgren Johan E
Kopia: gdal-dev at lists.maptools.org
Ämne: Re: [Gdal-dev] Read/Write Oracle Spatial
On 10/25/05, Hallgren Johan E <jhhal at wmdata.com> wrote:
>
> Reading from works fine but when I call the SetFeature method it fails.
>
>
>
> The error-message I can see in the Output win is:
>
> ERROR 1: OGROCITableLayer::SetFeature(-1) failed because
> there is no apparent FID column on table BAGGIS_LINES.
>
> What's wrong?
>
> What I want was to read a record, change some value and then write it back.
>
> Any assistance would be great.
Johan,
As the error message mentions, OGR was unable to establish an
integer primary key column to use with this table as the FID (feature
id). This makes it very difficult to update a row in place, since
I don't know which row the feature comes from.
When there is no known fid column, feature ids are assigned
sequentially by the reader but it isn't a meaningful fid.
However, I am quite surprised to see the message reporting the
feature as having fid -1 (OGRNullFID) instead of 0.
If your table has a primary key column you could set the
OGR_FID environment/config variable with the name of the
column so that it will be used as FID. There should be a
cpl.SetConfigOption() method available you can call like this:
CPL.cpl.SetConfigOption( "OCI_FID", "ID" )
On the FID issue, could you try checking the f.GetFID()
value after reading the feature. I am quite surprised that it
is 0.
BTW, I am impressed to see the C# bindings working so
well. I hadn't gotten to trying them yet myself.
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