[mapserver-users] oraclespatial query error 'function not implemented yet'

Rodrigo Cabral cabral at yadata.net
Fri Jan 11 08:40:36 EST 2002


Dear Hanna:

I plan to finish the rest of MapServer's Oracle Spatial functions anytime
soon. It's just that I don't have time right now to work with it. I'm
creating an Information System that's also linked to geographical
information, using Oracle Spatial. I'm using OCI's PHP functions to do the
query part you're trying to do.

I'm not sure if you're working with MapServer's CGI version and HTML
templates, or if you're already using MapScript and PHP (which would make
things easier). Anyway this is how it works.

Upon a click or selection in the (web) map, you must identify in your
html/javascript code the following variables:

- map image width and height (imgsize)
- current image extents (imgext)
- query coordinate: let's say a box query (x1, y1, x2, y2)

Then you should create a javascript function to convert (xi,yi) which are in
image coordinates to (qxi,qyi) in map coordinates. Here's my function:

<script language="javascript">
function DoQuery( url_query, x1, y1, x2, y2 )
{
  size = imgsize.split( /\+/ );
  ext = imgext.split( /\+/ );

  nx = eval( size[0] ) - 1;
  ny = eval( size[1] ) - 1;

  minx = eval( ext[0] );
  miny = eval( ext[1] );
  maxx = eval( ext[2] );
  maxy = eval( ext[3] );

  qx1 = x1*(maxx - minx)/nx + minx;
  qx2 = x2*(maxx - minx)/nx + minx;

  qy1 = (ny - y1)*(maxy - miny)/ny + miny;
  qy2 = (ny - y2)*(maxy - miny)/ny + miny;

  document.location = url_query + '?querybox=' + qx1 + '+' + qy1 + '+' + qx2
+ '+' + qy2;
}
</script>

Let's give some sample values to these variables:
imgsize = '300+200';
imgext = '1000+2000+3000+4000';
url_query = 'http://myhost/myquery.php';

This would mean that the image has 300 pixels for width, and 200 pixels for
height; and that current image extents are minx=1000, miny=2000, maxx=3000,
maxy=4000 (it varies as you pan, zoom in or out). As you can tell, this is
very similar to how MapServer CGI's version work with variables. You may
notice that Y coordinates are translated differently from X coordinates
because Y coordinates are top-down in image units and bottom-up in map
units; X coordinates on both cases are left-right.

Now, the file myquery.php will receive the query box, in map coordinates, so
it can use PHP OCI's functions to perform the queries. This is how the file
should looks like (note that '+' chars in the query box are converted to
spaces automatically for the PHP script):

<?php
// myquery.php
// input: querybox='x1 y1 x2 y2'
// output: query results

list( $x1, $y1, $x2, $y2 ) = split( " ", $querybox );

// if x1 equals x2 and y1 equals y2, then it's a point query
// thus, make it a box using 'buffer'
if ($x1==$x2 && $y1==$y2) {
  $buffer = 100; // in map units
  $x1 -= $buffer; $x2 += $buffer;
  $y1 -= $buffer; $y2 += $buffer;
}

// buils the query statement
$query= "
  SELECT *
  FROM mytable
  WHERE
    SDO_FILTER( mytable.shape,
      mdsys.sdo_geometry(
      2003, NULL, NULL,
      mdsys.sdo_elem_info_array( 1, 1003, 3),
      mdsys.sdo_ordinate_array( $x1, $y1, $x2, $y2 )),
      'querytype=window') = 'TRUE'
";

// connects to Oracle using $username, $password and $db
$username = "scott";
$password = "tiger";
$db = "";
$conn = OCILogon( $username, $password, $db );

// performs the query
$stmt = OCIParse( $conn, $query );
$success = OCIExecute( $stmt );

// print the results
if ($success) {
    // retrieve information using OCIFetchInto
    // prints it out, then we're done!
}

// disconnects from Oracle
$conn = OCILogoff( $conn );
?>

Now, the question is: isn't simplier using CGI's version of MapServer? Well,
could be. But here are the advantadges of this approach:
1) It's faster! Because you access directly Oracle's database, bypassing
MapServer.
2) It's more flexible! Because you can create your own query with custom
joins and the works!
3) Independent! Because "myquery.php" can receive queries from other
scripts, which enables you to allow the user to manually enter information
for the query! For instance, let's say you have the coordinate of a ship
given by a GPS and you want to know what do you have nearby. Just send the
GPS coordinates to your PHP query file and you have your query done!
MapServer is never used/needed in this case.

I will still finish MapServer's Oracle Spatial functions in the near future,
because it's important to have this option available to users. On the other
hand, that's certainly a feature I won't need to use because the one I just
showed you I consider to be better...

Please, feel free to contact me if you need anything else. I'm curious to
know if my solution worked for ya.

Cheers,
Rod.

----- Original Message -----
From: "Jensen, Hannah ERDC-CRREL-NH" <Hannah.Jensen at erdc.usace.army.mil>
To: <mapserver-users at lists.gis.umn.edu>
Sent: Thursday, January 10, 2002 8:03 PM
Subject: [mapserver-users] oraclespatial query error 'function not
implemented yet'



Hello.  I'm trying to query an Oracle spatial point layer and not having
much luck.  If a click finds no results, I get the expected error.  If it
finds a shape, I get:

msOracleSpatialLayerGetShape(): OracleSpatial error. Function not
implemented yet

Will this function be implemented soon?  Is there a workaround for now?
Thanks for any info!

Cheers,
Hannah

Hannah Jensen
(603) 646-4145
Remote Sensing / GIS Center
Cold Regions Research and Engineering Lab (CRREL)
US Army Corps of Engineers
72 Lyme Rd, Hanover, NH 03755-1290









More information about the mapserver-users mailing list