[Mapserver-users] automatic generation of location maps
James Jefferson
jj at aprsworld.net
Wed Sep 10 08:48:41 PDT 2003
Here is what I use to put points on a map from a mysql database:
function createAPRSAreaLayer( $db, $oImage ) {
$sql = sprintf("SELECT * FROM lastposition WHERE packet_date >=
date_sub(now(),INTERVAL %lf MINUTE) AND (latitude >= %lf && latitude <= %lf)
AND (longitude >= %lf && longitude <=
%lf)",$_REQUEST["minutes"],$GLOBALS["goMap"]->extent->miny,
$GLOBALS["goMap"]->extent->maxy,
$GLOBALS["goMap"]->extent->minx,$GLOBALS["goMap"]->extent->maxx);
$query = mysql_query($sql,$db);
$oLayer = $GLOBALS["goMap"]->getLayerByName("aprs");
$stationCount=0;
while ( $rec=mysql_fetch_array($query) ) {
$stationCount++;
/* Create the point shape */
$oShape = ms_newShapeObj(MS_SHAPE_POINT);
/* add the label */
$label = $rec["source"];
// if ( "" != $rec["status"] )
// $label .= "\n" . $rec["status"];
$oShape->set("text", $label);
$oShape->set("classindex",0);
/* Which is defined as a line with a single point */
$oLine = ms_newLineObj();
/* We add a point to the line */
$oLine->addXY((double) $rec["longitude"], (double) $rec["latitude"]);
/* We add the line to the shape */
$oShape->add($oLine);
/* Add the feature to the layer */
if ( -1 == $oLayer->addFeature($oShape) ) {
printf("Error adding feature!<BR>\n");
printf("lat: %lf lon: %lf source: %s
",$rec["latitude"],$rec["longitude"],$rec["source"]);
}
$oShape->free();
}
$oLayer->draw($oImage);
$GLOBALS["inViewCount"] = $stationCount;
return $stationCount;
}
You can see the source to more of the application at:
http://maps.aprsworld.net/mapserver/area/area.phps
And an example (work in progress) at:
http://maps.aprsworld.net/mapserver/area/index.phtml?maptype=area&minutes=2
-Jim
More information about the MapServer-users
mailing list