is this possible (make file)
Blaise
bpicinbono at WORLDONLINE.FR
Tue May 23 12:36:35 PDT 2006
Le Mardi 23 Mai 2006 21:18, Andrew Timmins a écrit :
> Hello,
>
> I am wondering if this is possible.
>
> On my map I allow the user to click and add many points on the map.
> The page stores the the X and Y of where the user clicked.
>
> I would like to take that information and convert it to a polygon shape and
> store it in ANY readable GIS application format (i.e .shp...)
>
> Any ideas ?
>
> right now I can allow users to draw the polygon on the map (using
> flash......) but i need to convert these spatial points to be read later on
> my other users who browse the map
>
>
> Andrew Timmins
Hi Andrew,
If using MapScript, no problem.
Here is a piece of old php_mapscript code that read several points from a
point layer ("ctmppoint") and create a new poly shape in the $sln layer (all
layers are shapefiles).
You may have to update it a bit, ie the id in the dbf file is always set to 0,
which might not be what you want... but you have the basic mapscript
functions, check for them in the doc.
Hope it helps.
Blaise
//// $stype=3; //// for line layer /////
$stype=5; //// for poly layer /////
$sclose=1; //// put first point at the end to close poly ////
$shapepath=$gpoMap->{shapepath};
$stmp="/ctmppoint";
$pointshpFileName="$shapepath"."$stmp";
$pointshpFile = ms_newShapeFileObj($pointshpFileName,-1);
$numpoint=$pointshpFile->{numshapes};
if ( (($numpoint>1) and ($stype==3)) or (($numpoint>2) and ($stype=="5")) )
{
$stmp="/$sln"; //// $sln=name of the line or poly layer ////
$lineshpFileName="$shapepath"."$stmp";
$lineshpFile = ms_newShapefileObj($lineshpFileName,-2);
$newShp = ms_newShapeObj(MS_SHP_LINE);
$aLine = ms_newLineObj();
for ($ipoint=0; $ipoint<$numpoint;$ipoint++)
{
$pointshp=$pointshpFile->getShape($ipoint);
$pointshpline=$pointshp->line(0);
$pointshppoint=$pointshpline->point(0);
$pt2x=$pointshppoint->{x};
$pt2y=$pointshppoint->{y};
$aLine->addXY($pt2x, $pt2y);
}
if ($sclose==1)
{
$pointshp=$pointshpFile->getShape(0);
$pointshpline=$pointshp->line(0);
$pointshppoint=$pointshpline->point(0);
$pt2x=$pointshppoint->{x};
$pt2y=$pointshppoint->{y};
$aLine->addXY($pt2x, $pt2y);
}
$newShp->add($aLine);
$lineshpFile->addShape($newShp);
$aLine->free();
$newShp->free();
$dbFile = dbase_open($lineshpFileName,2);
$c=0; ////// id=0 - may have to change that... ////
dbase_add_record($dbFile,$c);
dbase_close($dbFile);
$lineshpFile->free();
}
$pointshpFile->free();
More information about the MapServer-users
mailing list