addXY($x,$y);
}
$shape->add($line); # This adds the line with all the coordinates from the CGI
#$shape->setBounds(); # This initalizes the shape.
# Buffer as desired.
if(isset($buffer)) {
$shape = $shape->buffer($buffer); # Mapscript using GEOS to bufffer the shape
if(!isset($shape)) { # Check to make sure the function returned a valid shape, if not, error.
appError("Buffering Failed. Buffer size: $buffer. Verify mapscript was linked with GEOS and that the buffer is a positive-real number.");
}
}
# Create a new Coordinate string based on any potential buffering.
# This is needed because after the object has been buffered it will have a new coordinate string.
# This information is passed back to the GeoMOOSE client so that it can set the "mapshape" parameter
# which displays the layer highlighting.
$coordString = '';
for($line = 0; $line < $shape->{numlines}; $line++) {
$lineObj = $shape->line($line);
for($point = 0; $point < $lineObj->{numpoints}; $point++) {
$pointObj = $lineObj->point($point);
$coordString = $coordString.$pointObj->{x}.' '.$pointObj->{y}.' ';
}
}
# Write out a shapefile
$shapefile = ms_newShapefileObj($directory.'/'.$id, $shapeFileType);
if(!isset($shapefile)) { appError("Cannot Open Shapefile! ".$directory."/".$id.".shp\n"); }
$shapefile->addShape($shape);
# Store some useful information in a Shapefile
#$dbh = DBI->connect("DBI:XBase:$directory");
#$dbh->do("create table $id (title char(64), id char(64),area float, perimeter float)");
#$dbh->do("insert into $id values ('$title', '$id', $area, $perimeter)");
$dbFields = array(
array("title", "C", 64),
array("id", "C", 64),
array("area", "N", 64, 3),
array("perimeter", "N", 64, 3),
);
if(!dbase_create($directory.'/'.$id.'.dbf', $dbFields)) {
appError('Could not create database');
}
$dbase = dbase_open($directory.'/'.$id.'.dbf', 2);
if(!$dbase) {
appError('Could not open dbase file!');
}
dbase_add_record($dbase, array($title, $id, $area, $perimeter));
dbase_close($dbase);
# Give the client the ID back so it can reference it later
if($output == 'text') {
#print "Content-type: text/plain\n\n";
header('Content-type: text/plain');
print $id;
} elseif($output == 'xml') {
header('Content-type: text/xml');
print "