Open a shapefile and read its shapes' attributes

Pietro Giannini pgiannini at BYTEWISE.IT
Thu Jul 12 10:51:43 EDT 2007


you are right!!
the code is:

<?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);
         //  note the index: '$i+1'
         $aLineValues = dbase_get_record_with_names($LineDBFFile,$i+1);
         $RouteName  = $aLineValues["RouteName"];
         printf($RouteName );
         $Line->free();
      }
    }
    $LineFile->free();
    dbase_close($LineDBFFile);

?>

.................pg

-- 
Pietro Giannini
Bytewise srl - Area GIS
41°50'38.58"N 12°29'13.39"E

On Gio, Luglio 12, 2007 14:51, Guillaume Sueur wrote:
> Be careful, DBF index starts at 1, not 0 if I'm right !
>
>
> Pietro Giannini a écrit :
>> 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
>>
>>
>
> --
> Guillaume SUEUR
> Expert SIG et OpenSource
> NEOGEO
> 46 RUE MATABIAU
> 31000 TOULOUSE
> 06 65 58 88 82
> Site web : http://www.neogeo-online.net
>
>



More information about the mapserver-users mailing list