Query shapes in certain extent

G-Net Consulting joelf at GNETCONSULTING.COM
Wed Sep 1 13:31:58 EDT 2004


Lowell/List:

I updated my code, as you suggested.  The results are coming out
now, but seem to be a page behind.  An example:

I have states that have points in each.  So, say you choose
Florida.  It should have 247 points.  If you then choose Alaska,
it now says 247 (which was Florida from before).  If you go
to another state (that should have 0, it finds 7).

I'm also assuming the index pulled is the one in sensors.shx?  I
really need to pull the ID from sensors.dbf.

I'm attaching my code and map file segment.  Any/all suggestions
would be appreciated.

Thanks!

MAP File ========================

  LAYER
    NAME "sensors"
    STATUS ON
    DATA "./sensors"
    TYPE POINT
 CLASSITEM "ID"
    SYMBOLSCALE 10
    LABELITEM "ID"
    LABELCACHE ON
    POSTLABELCACHE TRUE
 TEMPLATE "sensors.html"
    METADATA
      "DESCRIPTION" "GMF Sensors "
   "RESULT_FIELDS" "ID"
    END
    CLASS
      NAME "Sensors"
   TEMPLATE "sensors.html"
      STYLE
        SYMBOL 4
        COLOR 0 255 0
        OUTLINECOLOR 0 0 0
        BACKGROUNDCOLOR 255 255 255
        SIZE 3
        MINSIZE 3
        MAXSIZE 100
      END
 END
END

PHP Code: ========================

// get our sensor layer
  $myLayer = $gmfMap->getLayerByName("sensors");
  $myLayer->set("status", 1);

  // create a rectangle object to search in and set the extent (from
querystring params)
  $rectObj = ms_newRectObj();
  $rectObj->setextent($_GET["minx"], $_GET["miny"], $_GET["maxx"],
$_GET["maxy"]);

  // query the points in the chosen space
  @$myLayer->queryByRect($rectObj);

  // find out how many results we found
  $shpCount = $myLayer->GetNumResults();

  // loop through our results, and process accordingly
  if ($shpCount) {
   for ($i = 0; $i < $shpCount; $i++) {
    // get our result
    $layerIndex = $myLayer->getResult($i);
    $arrShapes[] = $layerIndex->shapeindex;
   }
  }

Joel

----- Original Message -----
From: "Lowell Filak" <lfilak at medinaco.org>
To: "G-Net Consulting" <joelf at GNETCONSULTING.COM>;
<MAPSERVER-USERS at LISTS.UMN.EDU>
Sent: Wednesday, September 01, 2004 9:20 AM
Subject: Re: [UMN_MAPSERVER-USERS] Query shapes in certain extent


> The following message was sent by G-Net Consulting
> <joelf at GNETCONSULTING.COM> on Tue, 31 Aug 2004 14:50:11 -0400.
>
> > Hello list:
> >
> > What is the best way to access the shapes and locations of
> > points marked within a given map?  I have several hundred
> > points I need to find that are displayed from a given layer.
> > What's the best way to accomplish this?
> >
> > I currently have a layer that has over 5,000 points marked
> > through the US.  As they drill down, I plan to use JavaScript
> > to display information about each one.  In the dbf file, I have
> > an ID that corresponds to an ID in a MySQL table.  I just
> > to get the ID"s of just the one displayed inside the chosen
> > extent.
> >
> > I'm using PHP 4.3.3 with MapScript 4.2.1 on Redhat 9.
> >
> > Thanks in advance.
> >
> > Joel
>
> Joel;
>
> If you create a rectObj using the specified extent you can use
> layer->queryByRect to query the point(s) into the layer resultcache and
> then use layer->getResult & resultCacheMemberobj->shapeindex to retrieve
> the shapeindex for each of the resulting points.
> If your id in the mysql database corresponds to the shapeindex your all
> set. If not then you will need to use an xbase module to pull the nth
> (shapeindex) record from the dbf file to obtain the id that links to the
> id in the mysql table.
>
> Lowell
>



More information about the mapserver-users mailing list