Open a shapefile and read its shapes' attributes
Pietro Giannini
pgiannini at BYTEWISE.IT
Thu Jul 12 05:47:51 PDT 2007
Hi Knight,
the php_mapscript ShapefileObj object do not read the values of the shapes
(?!?), it seems.
You must to read the values in the .dbf file; the dbf entries are in the
same order of the shapes.
Your php need the "php_dbase" extension.
the code:
<?php
$Path = '\ms4w\apps\map\routes.shp';
// the dbf file identifier:
$LineDBFFile = dbase_open("\ms4w\apps\map\routes.dbf",0);
$LineFile = ms_newShapefileObj($Path,-1);
$numshapes = $LineFile->numshapes;
if($numshapes > 0)
{
for($i = 0; $i < $numshapes; $i++)
{
$Line = $LineFile->getShape($i);
$aLineValues = dbase_get_record_with_names($LineDBFFile,$i);
$RouteName = $aLineValues["RouteName"];
printf($RouteName );
$Line->free();
}
}
$LineFile->free();
dbase_close($LineDBFFile);
?>
ciao
...............................pg
--
Pietro Giannini
Bytewise srl - Area GIS
41°50'38.58"N 12°29'13.39"E
On Gio, Luglio 12, 2007 05:11, Jedi Knight wrote:
> Hi all,
> I want to open a line shapefile (routes.shp) and read attribute
> (RouteName)
> from it.
> My codes here:
> <?php
> $Path = '\ms4w\apps\map\routes.shp'; // must use full path [:(]
> $LineFile = ms_newShapefileObj($Path,-1); // open for read-only
> $numshapes = $LineFile->numshapes;
> if($numshapes > 0)
> {
> for($i = 0; $i < $numshapes; $i++)
> {
> $Line = $LineFile->getShape($i);
> $RouteName = $Line->values["RouteName"];
> printf($RouteName ); // it show nothing
> $Line->free();
> }
> }
> $LineFile->free();
> ?>
>
> But it doesn't works!
> Can someone explain to me. Thanks!
>
More information about the MapServer-users
mailing list