Something basic wrong with my querybyAttributes in PHP.

Neil Fincham neil at ASDF.CO.NZ
Tue Dec 11 18:23:06 EST 2007


Hi All,

	I am new to MapServer (And PHP) but I have found this list very useful
as well as the page on the MapServer website
http://mapserver.gis.umn.edu/docs/howto/phpmapscript-byexample .

	I have already managed to get the examples running but to truly
understand what I am doing I just need a bit of a pointer so I am doing
what I normally doing and getting back to the basics.

	What I am trying to do is query a map layer and then draw what is there
and display it.

My current PHP code is;-

######################## PHP BIT ########################
<?php

$map_path="../map/";
$mapFile = "Fips.map";
$qLayer = "LandUnits";
$qField = "ForestCode";
$qSelect = "KPNG";

$map = ms_newMapObj($map_path.$mapFile);

$layer=$map->getLayerByName($qLayer);

$layer->querybyAttributes($map, $qField, $qSelect, MS_MULTIPLE);

$image = $map->drawQuery();

// $image = $map->draw();

$image_url = $image->saveWebImage();

?>

<HTML>
 <HEAD>
     <TITLE>Example 1: Displaying a map</TITLE>
 </HEAD>
 <BODY>
     <IMG SRC=<?php echo $image_url; ?> >
 </BODY>
</HTML>

#############################################################

Relevant part of my MapFile;-  (Runs fine with the Demo code)

######################## Mapfile BIT ########################

LAYER
  NAME LandUnits
  METADATA
    "DESCRIPTION"   "Land Units"
    "RESULT_FIELDS" "ForestCode Descriptio"
  END
  LabelItem "Descriptio"
  LABELMAXSCALE 100000
  TYPE POLYGON
  STATUS ON
  DATA LU
  CLASS
    NAME "Land Units"
    COLOR 200 255 0
    OUTLINECOLOR 120 120 120
    TEMPLATE "ttt_query.html"

    NAME "Units"

    LABEL
      COLOR  255 0 0
      FONT sans-italic
      TYPE truetype
      SIZE 8
      POSITION AUTO
      PARTIALS FALSE
      OUTLINECOLOR 255 255 255
    END

  END
  TOLERANCE 5
END # Layer

###############################################################

Output from ogrinfo -al LU.dbf

######################## ShapeFile BIT ########################

INFO: Open of `LU.dbf'
      using driver `ESRI Shapefile' successful.

Layer name: LU
Geometry: Polygon
Feature Count: 3043
Extent: (2074167.884855, 5401865.320725) - (2967971.360273, 6735847.095329)
Layer SRS WKT:
PROJCS["GD_1949_New_Zealand_Map_Grid",
    GEOGCS["GCS_New_Zealand_1949",
        DATUM["New_Zealand_Geodetic_Datum_1949",
            SPHEROID["International_1924",6378388.0,297.0]],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]],
    PROJECTION["New_Zealand_Map_Grid"],
    PARAMETER["False_Easting",2510000.0],
    PARAMETER["False_Northing",6023150.0],
    PARAMETER["Longitude_Of_Origin",173.0],
    PARAMETER["Latitude_Of_Origin",-41.0],
    UNIT["Meter",1.0]]
OBJECTID: Integer (9.0)
Descriptio: String (25.0)
ForestCode: String (4.0)
CPT: Integer (9.0)
Stand: String (3.0)
SpeciesLab: String (25.0)
YOE: Integer (4.0)
StockedSta: String (20.0)
ProdStatus: String (15.0)
AreaHa: Real (19.11)
Source: Integer (4.0)
Source_Des: String (70.0)
FSC_Class: String (70.0)
Circa: String (4.0)
Regen: String (6.0)
RealForest: String (4.0)
CreatedBy: String (8.0)
CreatedDat: Date (10.0)
ModifiedBy: String (8.0)
ModifiedDa: Date (10.0)
LandUnit: Integer (9.0)
ParentLand: Integer (9.0)
GeoUnit: Integer (9.0)
GeoUnitTyp: Integer (4.0)
GeoUnitSeq: Integer (4.0)
Crop: Integer (9.0)
LandClass: String (20.0)
LandType: String (20.0)
SourceOrig: String (20.0)
SHAPE_Leng: Real (19.11)
SHAPE_Area: Real (19.11)

###############################################################

What I actually get to my browser is;-

######################## BrowserOutput ########################

Warning: [MapServer Error]: msDBFGetItemIndex(): Item 'Object' not
found. in 2.php on line 13

Warning: [MapServer Error]: msDrawMap(): Failed to draw layer named
'LandUnits'. in 2.php on line 15

Warning: [MapServer Error]: msDBFGetItemIndex(): Item 'Object' not
found. in 2.php on line 15

Warning: [MapServer Error]: msDBFGetItemIndex(): Item 'Object' not
found. in 2.php on line 15

Fatal error: Call to a member function saveWebImage() on a non-object in
2.php on line 19

################################################################

Line 13 is: $layer->querybyAttributes($map, $qField, $qSelect, MS_MULTIPLE);

Line 17 is: $image = $map->drawQuery();

	Sorry about the info flood but I always find that the more info the better.

	I am quite sure that I am just missing something basic but any help
would be appreciated.

Thanks

Neil



More information about the mapserver-users mailing list