"; print "GeoMOOSE Service Error"; print ""; print "

Service Message

"; print "".$msg.""; print ""; print ""; exit(0); } /* * writeShapeFile() * This is a very terse way to create a shapefile. * $shapeFileName - Filename for the shape file to write * $shapeFileType - Mapscript Shapefile Constant indicating whether the shape * file is to be point, line, polygon, etc. * $shapes - Array containing the shapes to be written to the shape file. * $class - Identifier to associate with the shape. */ function writeShapeFile($shapeFileName, $shapeFileType, $shapes, $class) { $fields = array( array("class", "C", 32) ); $shapefile = ms_newShapefileObj($shapeFileName, $shapeFileType); if(!isset($shapefile)) { appError("Cannot Open Shapefile! ".$shapeFileName.".shp\n"); } $dbaseFilename = $shapeFileName.'.dbf'; if(!dbase_create($dbaseFilename, $fields)) { appError('Could not create dbase file: '.$shapeFileName); } $dbase = dbase_open($dbaseFilename, 2); foreach ($shapes as $shape) { dbase_add_record($dbase, array($class)); $shapefile->addShape($shape); } dbase_close($dbase); $shapefile->free(); } /* * getShapesFromLayer() * Searches a layer in a map with a specific shape, returns an array of found shapes * $map - Map to search * $layer - Name of the layer to search or "*" to search all layers * $searchShape - Shape to be used in the search for other shapes. */ function getShapesFromLayer($map, $layerName, $searchShape) { $shapes = array(); # New array to hold results $map->getLayerByName($layerName)->set('status',MS_ON); $map->queryByShape($searchShape); # Query the map by the search shape for($l = 0; $l < $map->{numlayers}; $l++) { # Cycle through the layers $layer = $map->getLayer($l); # Get they layer object from the map. if($layer->{name} == $layerName or $layerName == '*') { # Check to make sure it's our layer of interest. $layer->open(); # Open the layer for operation. if($layer->getNumResults() > 0) { # Check to make sure we have SOME results for($result = 0; $result < $layer->getNumResults(); $result++) { # Get the member of the result set $queryResult = $layer->getResult($result); # Get the feature from that result. $queryFeature = $layer->getShape($queryResult->{tileindex}, $queryResult->{shapeindex}); array_push($shapes, $queryFeature); } } $layer->close(); # Close the layer } } return $shapes; } /* * getLayerColumnHash() * Returns a hash/dictionary/associative-array of the layer's columns. * If a layer contained the columns 'Name','Rank','Serial', then * this function would return an array with items 'Name' = 0, 'Rank' = 1, 'Serial' = 2 */ function getLayerColumnHash($layer) { $arr = array(); $items = $layer->getItems(); for($i = 0; $i < count($items); $i++) { $arr[$items[$i]] = $i; } return $arr; }