FW: [gdal-dev] OGR - Oracle problem

Clay, Bruce bclay at ball.com
Mon Mar 9 15:44:12 EDT 2009


Follow up

 

I am not sure which is a better solution speed wise but I did find 2
solutions to the problem I was having - 

 

 

The first solution that appears to work is to cast the returned distance
field to a real in the outer select statement

 

select OBJECTID, cast(Dist as real) from

    (select OBJECTID, sdo_nn_distance(1) Dist from

                    GEONAMES_SDO a1 where DSG LIKE 'PPL%' AND

                    sdo_nn(a1.shape, 

                        sdo_geometry(2001, null,

                            sdo_point_type((-84.48500000,-21.98100000,
NULL), null, null),

                            'sdo_num_res=100',1) = 'TRUE') where

                  Dist <= 0.09633643;

 

The second approach that appeared to work id from as code perspective is
to set the field type after the Execute SQL.  I am not sure how stable
this method is because the firt time I tried it after the first
GetNextFeature it did not work on the first feature but did work on the
rest.  I guess that indicates that the change has to be performed before
requesting the feature not before requesting the attribute.

 

            OGRLayer *queryLayer = outputDataSrc->ExecuteSQL(sqlquery,
NULL, "generic");

 

            if (queryLayer != NULL)

            {

                  OGRFeatureDefn *featureDef =
queryLayer->GetLayerDefn();

                  if (featureDef != NULL)

                  {

 

                        OGRFieldDefn *fieldDef =
featureDef->GetFieldDefn(1);

 

                        if (fieldDef != NULL)

                        {

                              fieldDef->SetType(OFTReal);

                        }

 

                        queryLayer->ResetReading();

 

                        OGRFeature *feature =
queryLayer->GetNextFeature();

                        while (feature != NULL)

                        {

 

 

Bruce

 

________________________________

From: gdal-dev-bounces at lists.osgeo.org
[mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Clay, Bruce
Sent: Friday, March 06, 2009 3:52 PM
To: gdal-dev at lists.osgeo.org
Subject: [gdal-dev] OGR - Oracle problem

 

 

When I issue the following SQL query through SqlPal I get 2 columns of
what appears to be valid data

 

select * from

 (select OBJECTID, sdo_nn_distance(1) Dist from

GEONAMES_SDO a1 where DSG LIKE 'PPL%' AND sdo_nn(a1.shape,

sdo_geometry(2001, null, sdo_point_type(-84.48500000,-21.98100000,
NULL), null, null),

'sdo_num_res=100',1) = 'TRUE');

 

Results

 

OBJECTID Dist

451323  .397194968358102

432828  .647925639080596

447967  .239182235498376

453566  .495207228227733

454057  .270980772175814

392983  .165016165538413

407235  .325487083888139

408026  .647925639080596

399747  .647925639080596

399036  .325487083888139

409567  .165016165538413

423135  .239182235498376

 

If I issue the same query through OGR ExecuteSql I get the first column
(OBJECTID) as it appears in SqlPal but the second column which should be
the distance comes back as type OFTInteger and the value is always zero
reguardless of where I call GetFieldAsString or GetFieldAsDouble.

 

Is there something else that has to be specified to get the correct data
type on this type of a query where a column is created dynamically?

 

Bruce

 

 

 



This message and any enclosures are intended only for the addressee.
Please  
notify the sender by email if you are not the intended recipient.  If
you are  
not the intended recipient, you may not use, copy, disclose, or
distribute this  
message or its contents or enclosures to any other person and any such
actions  
may be unlawful.  Ball reserves the right to monitor and review all
messages  
and enclosures sent to or from this email address.



This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090309/91260fe0/attachment-0001.html


More information about the gdal-dev mailing list