[mapserver-users] PHP mapscript using OracleSpatial
Jessica Clarke
Jessica.Clarke at forestrytas.com.au
Mon Jul 9 19:27:26 PDT 2012
Hi Andreas (and others),
Thank you for your assistance.
I have moved past my oracle issues now, but I'm having trouble with Mapserver.
The only error I get is
"Error in getString(): Parsing error near (DD):(line 463)"
I'll attach my code to help, but I'm not sure why I'm having this issue.
Any advice is very welcome.
Thank you.
Jess
###PHP###
<?php
//Call like: shape_name=ASSET&shape_id=19117&shape_type=MS_LAYER_POLYGON&rel_name=SURVEY&rel_id=42&rel_type=MS_LAYER_LINE ( http://tippy/relshptest/multiLayer3.php?shape_name=ASSET&shape_id=19117&shape_type=MS_LAYER_POLYGON&rel_name=SURVEY&rel_id=42&rel_type=MS_LAYER_LINE )
//
$oracle_user='user';
$oracle_pass='pass';
$oracle_db='db;
if(!extension_loaded('MapScript'))
{
dl('php_mapscript.dll');
}
$buffer=50;
if ($_GET['shape_name'])
{
//original shape
$shape_name = $_GET['shape_name'];
$shape_id = $_GET['shape_id'];
$shape_type = $_GET['shape_type'];
//related shape
$rel_name = $_GET['rel_name'];
$rel_id = $_GET['rel_id'];
$rel_type = $_GET['rel_type'];
switch ($shape_name)
{
//take the shape name input via the url and use this information to set the appropriate table view
//then to find the extent values using the select statement
//then set the data, and related data according to the type
case "ASSET":
$rel_view = $shape_name;
$query = "SELECT a.asset_id,
SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 1),
SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 2),
SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 1),
SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 2)
FROM fod.asset a, fod.related_asset_shape b
WHERE a.asset_id = b.asset_id
AND b.shape_id = ".$rel_id;
$data = "shape from (select asset_id, shape from fod.asset where asset_id = ".$shape_id.") using unique asset_id";
$rel_data = "shape from (select asset_id, shape_id, shape from fod.related_asset_shape where asset_id = ".$rel_id.") using unique shape_id";
break;
case "SURVEY":
$rel_view = $shape_name;
$query = "SELECT a.survey_id, SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 1), SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 2), SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 1), SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 2) FROM fod.survey a, fod.related_survey_shape b WHERE a.survey_id = b.survey_id AND b.shape_id = ".$rel_id;
$data = "shape from (select survey_id, shape from fod.survey where survey_id = ".$shape_id.") using unique asset_id";
$rel_data = "shape from (select survey_id, shape, shape_id from fod.related_survey_shape where survey_id = ".$rel_id.") using unique shape_id";
break;
case "OPERATION":
$rel_view = "opn";
$query = "SELECT a.operation_id, SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 1), SDO_GEOM.SDO_MIN_MBR_ORDINATE(a.shape, 2), SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 1), SDO_GEOM.SDO_MAX_MBR_ORDINATE(a.shape, 2) FROM fod.operation a, fod.related_opn_shape b WHERE a.operation_id = b.operation_id AND b.shape_id = ".$rel_id;
$data = "shape from (select operation_id, shape from fod.operation where operation_id = ".$shape_id.") using unique operation_id";
$rel_data = "shape from (select operation_id, shape, shape_id from fod.related_opn_shape where operation_id = ".$rel_id.") using unique shape_id";
break;
default:
}
//echo $rel_view;
$conn=OCILogon($oracle_user, $oracle_pass, $oracle_db);
//check connection
if(!$conn)
{exit("connection failed:" . $conn);}
else
//{ echo "hooray - connected: ". $conn;}
$asset_query = OCIParse($conn, $query);
oci_execute($asset_query);
$target_asset=oci_fetch_array($asset_query);
//Create new map object and set up some parameters
$map=ms_newMapObj('base2.map');
//Set map extent to target asset MBR +/- buffer value
$map->setExtent($target_asset[1]-$buffer, $target_asset[2]-$buffer, $target_asset[3]+$buffer, $target_asset[4]+$buffer);
//Set up original shape layer
$shape_layer=$map->getLayerByName("layer1");
$shape_layer->set("status", MS_ON);
$shape_layer->set("type", $shape_type);
$shape_layer->set("connectiontype", MS_ORACLESPATIAL);
$shape_layer->set("connection", $oracle_user."/".$oracle_pass."@".$oracle_db);
$shape_layer->set("data", $data);
//echo $data;
$shape_layer->setProcessing("CLOSE_CONNECTION=DEFER");
$shape_layer->setProjection('+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
//$shape_layer->set("maxscaledenom", 250001);
$shape_class=ms_newClassObj($shape_layer);
$shape_style=ms_newStyleObj($shape_class);
$shape_style->color->setRGB(199, 140, 218);
$shape_style2=ms_newStyleObj($shape_class);
$shape_style2->outlinecolor->setRGB(147, 37, 178);
$shape_style2->set("width", 2);
//Set up related shape layer
/*$rel_layer=$map->getLayerByName("layer2");
$rel_layer->set("status", MS_ON);
$rel_layer->set('type', $rel_type);
$rel_layer->set("connectiontype", MS_ORACLESPATIAL);
$rel_layer->set("connection", $oracle_user."/".$oracle_pass."@".$oracle_db);
$rel_layer->set("data", $rel_data);
//echo $rel_data;
$rel_layer->setProcessing("CLOSE_CONNECTION=DEFER");
$rel_layer->setProjection('+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
$rel_class=ms_newClassObj($rel_layer);
$rel_style=ms_newStyleObj($rel_class);
$rel_style->color->setRGB(199, 140, 218);
$rel_style->set("width", 3);
//echo 'layer2 done';
*/
//draw the map
$map_image=$map->draw();
$error=ms_GetErrorObj();
while($error && $error->code != MS_NOERR)
{
printf("Error in %s: %s<br>\n", $error->routine, $error->message);
$error = $error->next();
}
$map_image->saveWebImage(); //send image to web browser
}
?>
###MAPFILE###
MAP
NAME base2
STATUS ON
SIZE 800 600
EXTENT 227154 5165779 627108 5614539
UNITS METERS
IMAGECOLOR 234 255 255
SYMBOLSET "base.sym"
FONTSET "base.list"
PROJECTION
"proj=utm"
"zone=55"
"south"
"ellps=GRS80"
"towgs84=0,0,0,0,0,0,0"
"units=m"
"no_defs"
END
SHAPEPATH "E:\tilelib\"
QUERYMAP
STATUS ON
STYLE SELECTED
END
OUTPUTFORMAT
NAME 'AGG'
DRIVER AGG/PNG
IMAGEMODE RGB
END
WEB
IMAGEPATH "C:\htdocs\tmp\"
IMAGEURL "/tmp/"
END
LEGEND
STATUS OFF
END
SCALEBAR
STATUS EMBED
POSITION lr
STYLE 1
UNITS meters
TRANSPARENT ON
LABEL
COLOR 0 0 0
OUTLINECOLOR 255 255 255
FONT "verdana"
TYPE TRUETYPE
POSITION AUTO
PARTIALS FALSE
SIZE 8
BUFFER 1
END
END
[.....]
LAYER
NAME layer1
TYPE POLYGON
STATUS OFF
END
LAYER
NAME layer2
TYPE LINE
STATUS OFF
END
[.....]
LAYER
NAME "grid"
TYPE LINE
STATUS ON
CLASS
STYLE
OUTLINECOLOR 0 0 0
WIDTH 1
END
LABEL
COLOR 255 0 0
FONT "verdana"
TYPE truetype
SIZE 8
POSITION CC
PARTIALS FALSE
BUFFER 0
OUTLINECOLOR 255 255 255
SHADOWCOLOR 60 60 60
SHADOWSIZE 2 2
END
END
PROJECTION
"proj=utm"
"zone=55"
"south"
"ellps=GRS80"
"towgs84=0,0,0,0,0,0,0"
"units=m"
"no_defs"
END
GRID
LABELFORMAT DD
MAXARCS 4
MAXSUBDIVIDE 8
END
END
>>> "Eichner, Andreas - SID-NLKM" <Andreas.Eichner at sid.sachsen.de> 6/07/2012 5:56 PM >>>
Hello Jessica,
I've tested your code successfully on PHP MapScript v5.2.0.
> I have issues with
> oraclespatial, and I just keep getting errors that the layer
> can't be drawn.
What errors do you get? Something like "[...] Error: ORA-12154:
TNS:could not resolve the connect identifier specified"? Then you
might need to set some environment variables first. For example,
I set ORACLE_HOME, TNS_ADMIN, LC_CTYPE and NLS_LANG.
> The lack of error reporting from
> php hasn't been helping matters either ;)
You can execute your script on the command line via "php <scriptname>".
This will display errors as long as error_reporting(E_ALL) or similar
is set:
$ php test.php
Warning: [MapServer Error]: msDrawMap(): Failed to draw layer named
'ASSET'.
in /tmp/foo/test.php on line 53
Warning: [MapServer Error]: msOracleSpatialLayerOpen(): Cannot create
OCI Handlers. Connection failure. Check the connection string. Error:
ORA-12154: TNS:could not resolve the connect identifier specified
.
in /tmp/foo/test.php on line 53
Error in msDrawMap(): Failed to draw layer named 'ASSET'.<br>
HTH
---------------------------------------------------------------------------------------------------------------------------------------------
This transmission is intended solely for the person or organisation to whom it is addressed.
It is confidential and may contain legally privileged information.
If you have received this transmission in error, you may not use, copy or distribute it.
Please advise us by return e-mail or by phoning 61 3 6235 8333 and immediately delete the transmission in its entirety.
We will meet your reasonable expenses of notifying us.
Despite our use of anti-virus software, Forestry Tasmania cannot guarantee that this transmission is virus-free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20120710/46000a6c/attachment.htm>
More information about the MapServer-users
mailing list