[mapserver-users] PHP Mapscript - layer->queryByAttribute problem

Worth Lutz wal3 at mindspring.com
Thu Jun 4 09:43:58 EDT 2009


Using MapServer 5.4.0:

I have two shapefile layers in NC State Plane system, one in ft and one in
meters.  The PROJECTION in the layers allows the map to be drawn correctly.

My problem occurs when trying to use PHP mapscript to queryByAttribute.  I
am locating NC counties from two different shapefiles.  Using the layer
which is the same projection at the map there is no problem.  Using the
other layer, the bounds of the query result appear to be in meters and not
ft.  Is this normal?  Do I have to make the conversion?

Using mapserver 5.4.0 

PHP mapscript:

  $ms = ms_newMapObj( $mapfile );
  $ms->setSize($mapVpWidth,$mapVpHeight);
  $groupnames = $ms->getAllGroupNames();
  for($i=0; $i < sizeof($layerNames); $i++) {
    if(in_array($layerNames[$i],$groupnames)) {
      $layerIndexes = $ms->getLayersIndexByGroup($layerNames[$i]);
      for($j=0; $j < sizeof($layerIndexes); $j++) {
        $layer = $ms->getLayer($layerIndexes[$j]);
        $layer->set("status", MS_ON);
      }   
    } else {
      $layer = $ms->getLayerByName($layerNames[$i]);
      $layer->set("status", MS_ON);
    }
  }

  $layer = $ms->getLayerByName($layername);
  $layer->set('status', MS_ON);
  $layer->queryByAttributes($attribute, $expression, MS_MULTIPLE);
  $numresults = $layer->getNumResults();
  if ($numresults < 1) {
    $err->msg = 'No results in '.$layername.' for '.$attribute.' =
'.$expression.'.';
    $error = true;
  } else {
    $result = $layer->getResult(0);
    $layer->open();
    $shapeObj = $layer->getFeature($result->shapeindex);
    $layer->close();
    $minx = $shapeObj->bounds->minx;
    $miny = $shapeObj->bounds->miny;
    $maxx = $shapeObj->bounds->maxx;
    $maxy = $shapeObj->bounds->maxy;
    $ms->setExtent( $minx, $miny, $maxx, $maxy );
    $img = $ms->drawquery();
    $tmpMapImg = $img->saveWebImage();
  }

*Layer data from mapfile:

  LAYER
    NAME "county_outlines"
    TYPE POLYGON
    MINSCALE 1200
    MAXSCALEDENOM 3750001
    STATUS off
    PROJECTION
      "init=epsg:2264" # NAD 83 North Carolina (ftUS)
    END
    DATA CountyBoundaryShoreline
    TEMPLATE void
    CLASS
    	NAME "county lines"
      STYLE
        OUTLINECOLOR 128 128 128
      END
    END
  END

  LAYER
    NAME "county_outlines2"
    TYPE POLYGON
    MINSCALE 1200
    MAXSCALEDENOM 3750001
    STATUS off
    PROJECTION
      "init=epsg:32119" # NAD 83 North Carolina (meters US)
    END
    DATA cb100_poly
    TEMPLATE void
    LABELITEM "co_name"
    LABELMAXSCALEDENOM 1500000
    LABELMINSCALEDENOM  100000
    CLASS
    	NAME "cb100_poly"
      STYLE
        OUTLINECOLOR 200 0 0
      END
      LABEL
        COLOR 0 0 0
        #SHADOWCOLOR 218 218 218
        #SHADOWSIZE 2 2
        TYPE BITMAP
        SIZE tiny
        POSITION CC
        PARTIALS FALSE
        BUFFER 2
      END
    END
  END




More information about the mapserver-users mailing list