[Mapserver-users] Getting attributes of tiled shapefile data
Joe Bussell
joe at otsys.com
Wed Oct 8 11:33:39 PDT 2003
The trick is to use the LOCATION stored in the tile index. The call I
use is as follows:
my ( undef, $location ) =
$dbfTable->get_record( $tile, "LOCATION" );
my $dbfFile = $pm{SHAPEPATH} . "/" . $location . ".dbf";
I include the complete subroutine that I use on my tiled city data for a
demo.
HTH,
Joe Bussell
On Time Systems
################################### from On Time Systems demo code
# uses a tiled data set
sub getNearestCityName
{
my $lat = shift;
my $lon = shift;
my $response = "";
if ( $lat && $lon )
{
my $queryPt = new mapscript::pointObj();
$queryPt->{x} = $lon;
$queryPt->{y} = $lat;
my $map = new mapscript::mapObj( $pm{MAPFILE} )
or croak('Unable to Open Default MapFile!');
$map->{shapepath} = $pm{SHAPEPATH} . "/";
my $layerObj = undef;
$layerObj = $map->getLayerByName('cityCenterIn');
$layerObj->{status} = $mapscript::MS_ON;
$layerObj->{type} = $mapscript::MS_LAYER_POINT;
$layerObj->{tileindex} = $pm{SHAPEPATH} . "/td_sm.shp";
if( $layerObj->queryByPoint( $map, $queryPt,
$mapscript::MS_SINGLE, 0 ) )
{
$response .= "";
}
else
{
my $results = $layerObj->{resultcache};
my $num_results = $results->{numresults};
my $rslt = $layerObj->getResult(0);
my $tile = $rslt->{tileindex};
# $response .= "<BR>\nFound tileindex at: $tile.<br>\n";
my $dbfFileName = $pm{SHAPEPATH} . "/td_sm.dbf";
my $fn = "";
if ( $dbfFileName =~ /(.*)/ ) # this is not real taint
# checking. You should
# use a real regex
{
$fn = $1;
}
my $dbfTable = new XBase("name" => $fn )
or croak "Cannot open dbfFile $fn $!\n";
my ( undef, $location ) =
$dbfTable->get_record( $tile, "LOCATION" );
my $record = $rslt->{shapeindex};
# $response .= "<BR>\nFound point at: $record.<br>\n";
my $dbfFile = $pm{SHAPEPATH} . "/" . $location . ".dbf";
if ( $dbfFile =~ /(.*)/ ) # this is not real taint
# checking. You should
# use a real regex
{
$fn = $1;
}
my $dbfT= new XBase("name" => $fn )
or croak "Cannot open dbfFile $fn $!\n";
my ( $deleted, $name )
= $dbfT->get_record( $record, "NAME" );
$response .= "\n<BR>Nearest City: $name<BR>\n";
}
undef $map;
}
return $response;
}
Sean Gillies wrote:
> I'm using a layer with tiled shapefile data in a MapScript app. When using
> the query* methods I get set of results and each result has tileindex and
> shapeindex attributes so that I can get get the appropriate shape from
> the shapefile.
>
> However, how about the shape attributes? With untiled data in one
> shapefile,
> I'd just get the appropriate record from the single dbf file using dbflib
> (Python) or XBase (Perl). But now that the attributes are spread across
> N dbf files, I'm at a loss on which dbf file and which record given the
> pair of tileindex and shapeindex.
>
> Perhaps it's possible to access the result.tileindex (or tileindex-1)
> record of
> the layer's tileindex dbf file to find the appropriate shapefile and then
> get the result.shapeindex record from that shapefile's dbf? I'd be
> grateful
> to hear about a less convoluted way!
>
> cheers,
> Sean
>
> --
> Sean Gillies
> sgillies at frii dot com
> http://www.frii.com/~sgillies
>
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
More information about the MapServer-users
mailing list