[mapserver-users] getting field names using mapscript

2008-11-06 Thread Jochen Wagner
Hi list,
I would like to list from any layer ($ qlayer) only the field names of
the attribute tables and the number of objects in the table.

With this code it works already:

//loading mapfile
$map= ms_newMapObj($mapfilepath.'\
demo.map');

//set layer
$layer = $map-getLayerByName($qlayer);

//rectquery via mapextent
@$datQuery = $layer-queryByRect($map-extent);

//if query is successful
if ($datQuery == MS_SUCCESS) {
 //number of objects
 $resnum = $layer-getNumResults();
 echo 'Anzahl: '.$resnum.'br';

 $layer-open();
 $result = $layer-getResult(0);
 $shpobj = $layer-getShape($result-tileindex,$result-shapeindex);

 //read attribute table
 $attr = $shpobj-values;
 foreach($attr as $name=$wert) {
 echo 'Feld: '.$name.'br';
 }
}
$shpobj-free();
$layer-close();

However, this method has the disadvantage using a layers with many
records the script takes a very long time, I guess because I have a
query about the whole issue run.
Has someone an approach for me, getting
1. the field names of the table and
2. the number of objects in the table
performantly using MapScript ?
thanks
Jo
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] getting field names using mapscript

2008-11-06 Thread Jochen Wagner
thanks, works fine and fast for each layer:

$layer-open();
$myitems = $layer-getItems();

foreach($myitems as $item) {
echo $item.br;
}
$layer-close();

but how can I get the numer of records without a query?
Jo


2008/11/6 Umberto Nicoletti [EMAIL PROTECTED]:
 You can use the items array on the layer object to get the field names

 On Thu, Nov 6, 2008 at 12:10 PM, Jochen Wagner
 [EMAIL PROTECTED] wrote:
 Hi list,
 I would like to list from any layer ($ qlayer) only the field names of
 the attribute tables and the number of objects in the table.

 With this code it works already:

 //loading mapfile
 $map= ms_newMapObj($mapfilepath.'\
 demo.map');

 //set layer
 $layer = $map-getLayerByName($qlayer);

 //rectquery via mapextent
 @$datQuery = $layer-queryByRect($map-extent);

 //if query is successful
 if ($datQuery == MS_SUCCESS) {
  //number of objects
  $resnum = $layer-getNumResults();
  echo 'Anzahl: '.$resnum.'br';

  $layer-open();
  $result = $layer-getResult(0);
  $shpobj = $layer-getShape($result-tileindex,$result-shapeindex);

  //read attribute table
  $attr = $shpobj-values;
  foreach($attr as $name=$wert) {
 echo 'Feld: '.$name.'br';
  }
 }
 $shpobj-free();
 $layer-close();

 However, this method has the disadvantage using a layers with many
 records the script takes a very long time, I guess because I have a
 query about the whole issue run.
 Has someone an approach for me, getting
 1. the field names of the table and
 2. the number of objects in the table
 performantly using MapScript ?
 thanks
 Jo
 ___
 mapserver-users mailing list
 mapserver-users@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/mapserver-users


___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] getting field names using mapscript

2008-11-06 Thread Umberto Nicoletti
Sorry don't know that :-(

On Thu, Nov 6, 2008 at 2:32 PM, Jochen Wagner [EMAIL PROTECTED]
wrote:
 thanks, works fine and fast for each layer:

 $layer-open();
 $myitems = $layer-getItems();

 foreach($myitems as $item) {
echo $item.br;
 }
 $layer-close();

 but how can I get the numer of records without a query?
 Jo


 2008/11/6 Umberto Nicoletti [EMAIL PROTECTED]:
 You can use the items array on the layer object to get the field names

 On Thu, Nov 6, 2008 at 12:10 PM, Jochen Wagner
 [EMAIL PROTECTED] wrote:
 Hi list,
 I would like to list from any layer ($ qlayer) only the field names of
 the attribute tables and the number of objects in the table.

 With this code it works already:

 //loading mapfile
 $map= ms_newMapObj($mapfilepath.'\
 demo.map');

 //set layer
 $layer = $map-getLayerByName($qlayer);

 //rectquery via mapextent
 @$datQuery = $layer-queryByRect($map-extent);

 //if query is successful
 if ($datQuery == MS_SUCCESS) {
  //number of objects
  $resnum = $layer-getNumResults();
  echo 'Anzahl: '.$resnum.'br';

  $layer-open();
  $result = $layer-getResult(0);
  $shpobj = $layer-getShape($result-tileindex,$result-shapeindex);

  //read attribute table
  $attr = $shpobj-values;
  foreach($attr as $name=$wert) {
 echo 'Feld: '.$name.'br';
  }
 }
 $shpobj-free();
 $layer-close();

 However, this method has the disadvantage using a layers with many
 records the script takes a very long time, I guess because I have a
 query about the whole issue run.
 Has someone an approach for me, getting
 1. the field names of the table and
 2. the number of objects in the table
 performantly using MapScript ?
 thanks
 Jo
 ___
 mapserver-users mailing list
 mapserver-users@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/mapserver-users



___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] getting field names using mapscript

2008-11-06 Thread Steve Lime
If you're using a shapefile however you can do something like:

  // in perl
  $shapefile = new mapscript::shapefileObj('myshapefile', -1);
  print $shapefile-{numshapes};

There is a getNumFeatures() method for layer objects although I don't know if 
it is widely implemented.

Steve

 On 11/6/2008 at 8:10 AM, in message
[EMAIL PROTECTED], Umberto
Nicoletti [EMAIL PROTECTED] wrote:
 Sorry don't know that :-(
 
 On Thu, Nov 6, 2008 at 2:32 PM, Jochen Wagner [EMAIL PROTECTED]
 wrote:
 thanks, works fine and fast for each layer:

 $layer-open();
 $myitems = $layer-getItems();

 foreach($myitems as $item) {
echo $item.br;
 }
 $layer-close();

 but how can I get the numer of records without a query?
 Jo


 2008/11/6 Umberto Nicoletti [EMAIL PROTECTED]:
 You can use the items array on the layer object to get the field names

 On Thu, Nov 6, 2008 at 12:10 PM, Jochen Wagner
 [EMAIL PROTECTED] wrote:
 Hi list,
 I would like to list from any layer ($ qlayer) only the field names of
 the attribute tables and the number of objects in the table.

 With this code it works already:

 //loading mapfile
 $map= ms_newMapObj($mapfilepath.'\
 demo.map');

 //set layer
 $layer = $map-getLayerByName($qlayer);

 //rectquery via mapextent
 @$datQuery = $layer-queryByRect($map-extent);

 //if query is successful
 if ($datQuery == MS_SUCCESS) {
  //number of objects
  $resnum = $layer-getNumResults();
  echo 'Anzahl: '.$resnum.'br';

  $layer-open();
  $result = $layer-getResult(0);
  $shpobj = $layer-getShape($result-tileindex,$result-shapeindex);

  //read attribute table
  $attr = $shpobj-values;
  foreach($attr as $name=$wert) {
 echo 'Feld: '.$name.'br';
  }
 }
 $shpobj-free();
 $layer-close();

 However, this method has the disadvantage using a layers with many
 records the script takes a very long time, I guess because I have a
 query about the whole issue run.
 Has someone an approach for me, getting
 1. the field names of the table and
 2. the number of objects in the table
 performantly using MapScript ?
 thanks
 Jo
 ___
 mapserver-users mailing list
 mapserver-users@lists.osgeo.org 
 http://lists.osgeo.org/mailman/listinfo/mapserver-users 




___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] getting field names using mapscript

2008-11-06 Thread Nicol Hermann
Hi Jochen,

Assuming you are using Shapefiles maybe you can achieve your second goal
with the base module of PHP

http://de3.php.net/manual/de/function.dbase-numrecords.php

HTH
Nicol


Am Donnerstag, den 06.11.2008, 12:10 +0100 schrieb Jochen Wagner:
 Hi list,
 I would like to list from any layer ($ qlayer) only the field names of
 the attribute tables and the number of objects in the table.
 
 With this code it works already:
 
 //loading mapfile
 $map= ms_newMapObj($mapfilepath.'\
 demo.map');
 
 //set layer
 $layer = $map-getLayerByName($qlayer);
 
 //rectquery via mapextent
 @$datQuery = $layer-queryByRect($map-extent);
 
 //if query is successful
 if ($datQuery == MS_SUCCESS) {
  //number of objects
  $resnum = $layer-getNumResults();
  echo 'Anzahl: '.$resnum.'br';
 
  $layer-open();
  $result = $layer-getResult(0);
  $shpobj = $layer-getShape($result-tileindex,$result-shapeindex);
 
  //read attribute table
  $attr = $shpobj-values;
  foreach($attr as $name=$wert) {
  echo 'Feld: '.$name.'br';
  }
 }
 $shpobj-free();
 $layer-close();
 
 However, this method has the disadvantage using a layers with many
 records the script takes a very long time, I guess because I have a
 query about the whole issue run.
 Has someone an approach for me, getting
 1. the field names of the table and
 2. the number of objects in the table
 performantly using MapScript ?
 thanks
 Jo
 ___
 mapserver-users mailing list
 mapserver-users@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/mapserver-users

___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users