Shapefile field problem

Nicol Hermann mapserver at GEOWORLD.DE
Tue Dec 7 17:29:14 EST 2004


Try adding a template tag to the layer section in your mapfile
e.g.
TEMPLATE "dummy.html"

getNumResults() are now 1

Nicol

Am Di, den 07.12.2004 schrieb Abe Gillespie um 23:19:
> Ok, you've proven to me you can *force* MapServer to give you the names 
> of problem fields.  But try this one (use the newly edited DBF file):
> 
> <html>
> <body>
>       <?
>               dl("php_mapscript.so");
>               $map = ms_newMapObj("/Users/abe/Sites/ms_test/test.map");
>               for ($i = 0; $i < $map->numlayers; $i++)
>               {
>                       $l = $map->getLayer($i);
>                       putBrLine($l->name.", type: ".$l->type);
> 
>                       // Query test.
>                       @$l->queryByAttributes("CITY", "/foo/", MS_MULTIPLE);
>                       putBrLine($l->getNumResults());
> 
>                       if ($l->data != null)  // Shape files with data.
>                       {
>                               $l->open();
>                               $s = $l->getShape(-1, 0);
>                               $vals = $s->values;
>                               putBrLine("field count: ".count($vals));
>                               /*
>                               while ($fld = current($vals))
>                               {
>                                       putBrLine("&nbsp;&nbsp;".key($vals));
>                                       next($vals);
>                               }
>                               */
>                               foreach ($vals as $key => $val) {
>                                       printf ("%s -- %s<br>\n", $key, $val);
>                               }
>                               $s->free();
>                               $l->close();
>                       }
>               }
> 
>               function putBrLine($line)
>               {
>                       echo "$line<br>\n";
>               }
>       ?>
> </body>
> </html>
> 
> For me I get 0 as the number of results but you can clearly see the 
> value getting dumped out.  Barring I didn't screw up the query, this is 
> a problem no?
> 
> Thanks as always.
> -Abe
> 
> 
> ______________________________________________________________________
> On Dec 7, 2004, at 4:30 PM, Nicol Hermann wrote:
> 
> > Hi Abe,
> >
> > i modified your script.
> > Instead of 'while' i use the following 'foreach' loop.
> >
> > foreach ($vals as $key => $val) {
> >    printf ("%s -- %s\n", $key, $val);
> > }
> >
> > This statement returns all 54 fields of your shapefile.
> >
> > HTH
> > Nicol
> >
> >
> > Am Di, den 07.12.2004 schrieb Abe Gillespie um 22:17:
> >> The problem with adding a value for that attribute corrupts the test
> >> case.  Can you try the following PHP code and compare your results 
> >> with
> >> mine?
> >>
> >> [php]
> >> <html>
> >> <body>
> >>         <?
> >>                 dl("php_mapscript.so");
> >>                 $map = 
> >> ms_newMapObj("/Users/abe/Sites/ms_test/test.map");
> >>                 for ($i = 0; $i < $map->numlayers; $i++)
> >>                 {
> >>                         $l = $map->getLayer($i);
> >>                         putBrLine($l->name.", type: ".$l->type);
> >>                         if ($l->data != null)  // Shape files with 
> >> data.
> >>                         {
> >>                                 $l->open();
> >>                                 $s = $l->getShape(-1, 0);
> >>                                 $vals = $s->values;
> >>                                 putBrLine("field count: 
> >> ".count($vals));
> >>                                 while ($fld = current($vals))
> >>                                 {
> >>                                         
> >> putBrLine("&nbsp;&nbsp;".key($vals));
> >>                                         next($vals);
> >>                                 }
> >>                                 $s->free();
> >>                                 $l->close();
> >>                         }
> >>                 }
> >>
> >>                 function putBrLine($line)
> >>                 {
> >>                         echo "$line<br>¥n";
> >>                 }
> >>         ?>
> >> </body>
> >> </html>
> >>
> >> [output]
> >> test, type: 2
> >> field count: 54
> >>    ACAD_TEXT
> >>    COUNT
> >>    ACCOUNT_NU
> >>
> >> See how there's a discrepancy between the field count and the number 
> >> of
> >> field names that get dumped?  From my experience, the field just after
> >> ACCOUNT_NU has a NULL value.  I see the same behavior on my Mac OS X
> >> and Debian Linux installs.
> >>
> >> -Abe
> >>
> >> On Dec 7, 2004, at 2:15 PM, Jeff McKenna wrote:
> >>
> >>> Abe,
> >>>
> >>> I made a tiny mapfile with your test shp, and i see labels properly 
> >>> in
> >>> MapServer with it.  I added an attribute in the "OWNERS_NAM" field 
> >>> and
> >>> I successfully displayed it in mapserver.  Am i misunderstanding your
> >>> problem somehow?  (mapfile below)
> >>>
> >>> jeff
> >>>
> >>> MAP
> >>>   NAME "field-test"
> >>>   STATUS ON
> >>>   EXTENT 1260565.500000 941362.000000 1261605.125000 942198.625000
> >>>   SIZE 400 300
> >>>   SHAPEPATH "D:/DMSG/projects/mapserver-bugs/"
> >>>   SYMBOLSET "../etc/symbols.sym"
> >>>   FONTSET "../etc/fonts.txt"
> >>>   IMAGETYPE gif
> >>>   IMAGECOLOR 255 255 255
> >>>   UNITS METERS
> >>>   WEB
> >>>     IMAGEPATH "/ms4w/tmp/ms_tmp/"
> >>>     IMAGEURL "/ms_tmp/"
> >>>     METADATA
> >>>     END
> >>>   END
> >>>
> >>>   OUTPUTFORMAT
> >>>     NAME "gif"
> >>>     MIMETYPE "image/gif"
> >>>     DRIVER "GD/GIF"
> >>>     EXTENSION "gif"
> >>>     IMAGEMODE PC256
> >>>     TRANSPARENT FALSE
> >>>   END
> >>>
> >>> LAYER
> >>>   NAME test
> >>>   TYPE POLYGON
> >>>   STATUS ON
> >>>   DATA test
> >>>   LabelItem "OWNERS_NAM"
> >>>   CLASS
> >>>     NAME "ttt"
> >>>     COLOR 0 255 0
> >>>     LABEL
> >>>       COLOR  255 0 0
> >>>       FONT fritqat-italic
> >>>       TYPE truetype
> >>>       SIZE 8
> >>>       POSITION AUTO
> >>>       PARTIALS FALSE
> >>>       OUTLINECOLOR 255 255 255
> >>>     END
> >>>   END
> >>> END # Layer
> >>>
> >>> END
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> Abe Gillespie wrote:
> >>>> I do appreciate the help, but I'm not looking for an "external to
> >>>> MapServer" way of getting access to my DBF field values.  I just use
> >>>> my
> >>>> PHP script to *reveal* problematic shapefile fields.  When there is 
> >>>> a
> >>>> problem it's unusable to MapServer!  I.e.: I can't use the field for
> >>>> labelling.
> >>>> -Abe
> >>>> On Dec 7, 2004, at 11:27 AM, Ryan, Adam wrote:
> >>>>> Abe,
> >>>>>
> >>>>> Here's a routine I use to get the header information (field info)
> >>>>> from
> >>>>> a dbf
> >>>>> file.
> >>>>>
> >>>>> //      ==========      iDbf_fields     ==============
> >>>>> //      $f is a dbf file path, returns an array of field arrays
> >>>>> function iDbf_fields($f){
> >>>>>         $h = fopen($f,"rb");
> >>>>>         $a =
> >>>>> unpack("cversion/cyy/cmm/cdd/inumrecs/sheadsize/
> >>>>> srecsize",fread($h,12));
> >>>>>         fread($h,20);   //skip some reserved space
> >>>>>         for($i=0;$i<($a["headsize"]-33)/32;$i++){
> >>>>>                 $fa = array();
> >>>>>                 $fname = trim(fread($h,11));
> >>>>>                 $fa["type"] = fread($h,1);
> >>>>>                 fread($h,4);
> >>>>>                 $fa =
> >>>>> array_merge($fa,unpack("Clen/Cpre",fread($h,2)));
> >>>>>                 fread($h,14);
> >>>>>                 $flds[$fname] = $fa;
> >>>>>         }
> >>>>>         fclose($h);
> >>>>>         return $flds;
> >>>>> }
> >>>>>
> >>>>> When I generate a result table I'll go through the array like this:
> >>>>> ($so is
> >>>>> the shape Object)
> >>>>>
> >>>>>                         foreach($flds as $fname => $fA){
> >>>>>                                 $val = $so->values[$fname];
> >>>>>                                 if ($val==null)$val="&nbsp";
> >>>>>                                 $val = str_replace("  ","
> >>>>> &nbsp;",$val);
> >>>>>                                 if ($fA["type"]=="D"){$val =
> >>>>> substr($val,4,2)."-".substr($val,6,2)."-".substr($val,0,4);}
> >>>>>                                 echo "<td>$val</td>";}
> >>>>>                 }
> >>>>>
> >>>>>
> >>>>> Cheers to all,
> >>>>>
> >>>>> Adam
> >>>>>
> >>>>>> -----Original Message-----
> >>>>>> From: Abe Gillespie [mailto:agillesp at VT.EDU]
> >>>>>> Sent: Monday, December 06, 2004 5:14 PM
> >>>>>> To: MAPSERVER-USERS at LISTS.UMN.EDU
> >>>>>> Subject: Re: [UMN_MAPSERVER-USERS] Shapefile field problem
> >>>>>>
> >>>>>>
> >>>>>> It's a regular shapefile.  I think I've mostly narrowed it
> >>>>>> down.  It seems to me (though I may be completely off) that
> >>>>>> MapServer loads the first record of the DBF in order to get
> >>>>>> the field definitions.  If the first record has a string
> >>>>>> field and the value is zero length it won't give me the field
> >>>>>> (though the field count is always correct).  In addition, it
> >>>>>> won't give me any fields after that either.  If, however, I
> >>>>>> make sure that field has some value (a dash, an "x",
> >>>>>> whatever) then the field definition will come in correctly.
> >>>>>> I still haven't narrowed down a problematic number field
> >>>>>> though.  Mind you, this is all done in MapServer PHP v. 4.2.0.
> >>>>>>
> >>>>>> -Abe
> >>>>>>
> >>>>>> On Dec 6, 2004, at 6:15 PM, Daniel Morissette wrote:
> >>>>>>
> >>>>>>> Abe Gillespie wrote:
> >>>>>>>
> >>>>>>>> A good amount of fields aren't showing up in MapServer for
> >>>>>>
> >>>>>> me.  I use
> >>>>>>
> >>>>>>>> the following PHP script to dump out all layers and their
> >>>>>>
> >>>>>> fields for
> >>>>>>
> >>>>>>>> debugging.  Does MapServer have problems with certain data
> >>>>>>
> >>>>>> types or
> >>>>>>
> >>>>>>>> certain values in a row?
> >>>>>>>>
> >>>>>>>
> >>>>>>> Are you using a tiled shapefile layer or is this a regular
> >>>>>>
> >>>>>> shapefile
> >>>>>>
> >>>>>>> layer?
> >>>>>>>
> >>>>>>> -- 
> >>>>>>> ------------------------------------------------------------
> >>>>>>>  Daniel Morissette               dmorissette at dmsolutions.ca
> >>>>>>>  DM Solutions Group              http://www.dmsolutions.ca/
> >>>>>>> ------------------------------------------------------------
> >>>>>>>
> >>>>>>
> >>>>>
> >>>
> >>>
> >>> -- 
> >>> Jeff McKenna
> >>> GIS Specialist
> >>> DM Solutions Group Inc.
> >>> http://www.dmsolutions.ca
> >>>
> >
-- 
          \\://
          (o -)      Dipl.-Geogr. Nicol Hermann
-------ooO-(_)-Ooo-----------------------------------------------
                     Chattenstraße 67  
  .oooO              55130 Mainz 
  (   )   Oooo.      Tel. 06131/6007550  
---\ (----(   )---------------------------------------------------
    \_)    ) /       http://www.nicol.info
          (_/        E-Mail: nicol at nicol.info


WWW-Tip!
--------
Geographisches Informationssystem
http://www.geoworld.de/



More information about the mapserver-users mailing list