MyGIS, Mapfile, and MapScript
Don Deskins
dldeskins at GMAIL.COM
Mon Apr 18 07:42:39 PDT 2005
Hey all,
I have questions about MyGIS and mapfile.
I have an area that I would like to display parcels of land and search
for a parcel by parcelid. I use two layers for the parcels: one layer
to display all of the parcels at a certain level and the second to
highlight the selected parcel. I have gotten my application to work
using shp/dbf/shx/qix files, but it is extremely slow when searching
for a parcelid (e.g., 25 seconds). The major time delay is searching
for a particular parcel id.
Using shp2mysql.pl, we have gotten the data into the mysql db. I
indexed on the parcel id. I am having trouble now filtering for the
parcelid. After getting several errors, I decided to see if I could
display the first layer using the db. It showed up nicely, but I am
still getting errors on my queried layer.
Here is what I have in the mapfile:
#layer to display all of the parcels
LAYER
NAME "Parcels"
STATUS ON
TYPE POLYGON
CONNECTIONTYPE mygis
CONNECTION "host:dbname:user:pass:bin:"
DATA "geo from Parcels feature, Parcels_bin geometry"
CLASS
OUTLINECOLOR 0 255 0
TEMPLATE "template.html"
END
MAXSCALE 40000
TOLERANCE 0
TOLERANCEUNITS PIXELS
END
# layer to display selected parcel
LAYER
NAME "Parcels2"
STATUS OFF
TYPE POLYGON
CONNECTIONTYPE mygis
CONNECTION "host:dbname:user:pass:bin::"
DATA "geo,PARCELID from Parcels2 feature, Parcels2_bin geometry"
FILTER "feature.PARCELID='C0244R F00005'"
CLASS
Name "MAP"
OUTLINECOLOR 0 255 0
TEMPLATE "template.html"
END
MAXSCALE 40000
TOLERANCE 0
TOLERANCEUNITS PIXELS
END
Here is the code that I use to query for the parcel id:
<?php
case 'parcelQuery':
$query=true;
require_once("connection.php");
// check to see if the Parcel id is in another table first.
$sql = "SELECT * FROM PARDAT WHERE PARID='" . $_REQUEST['parcelid'] . "'";
$result = mysql_query($sql);
if(mysql_num_rows($result))
{
$my_layer=$map->getLayerByName("Parcels2");
if($my_layer->queryByAttributes('PARCELID', $_REQUEST['parcelid'],
MS_SINGLE)==MS_SUCCESS)
{
$my_layer->open();
$my_layer->set("status",MS_ON);
for($k=0; $k < $my_layer->getNumResults(); $k++)
{
$my_resultcache=$my_layer->getResult($k);
$my_shape=$my_layer->getShape($my_resultcache->tileindex,
$my_resultcache->shapeindex);
$my_array=$my_shape->values;
$map->setextent($my_shape->bounds->minx-100, $my_shape->bounds->miny-100,
$my_shape->bounds->maxx+100, $my_shape->bounds->maxy+100);
//print_r($my_array);
}
$my_layer->close();
}
}
else
{
print "Parcel ID " . $_REQUEST['parcelid'] . " not found. <br>";
$_REQUEST['parcelid'] = "";
}
break;
?>
I get the following warnings and therefore errors:
Warning: [MapServer Error]: msMYGISLayerGetShapeRandom(): GetShape
called on MYGIS layer with invalid DB query results. in <path to
script> on line 153
Warning: [MapServer Error]: SELECT feature.id, feature.vertices,
geometry.WKB_GEOMETRY , fea mysql query failed : mysql query failed in
<path to script> on line 153
Line 153 is this line:
if($my_layer->queryByAttributes('PARCELID', $_REQUEST['parcelid'],
MS_SINGLE)==MS_SUCCESS)
This script works using the shp files.
Thanks,
Don
More information about the MapServer-users
mailing list