I'm a beginner in this field and i've plotted the postgis database table points in geomoose in 3857 projection.Configured identify tool and it works .But the search query for postgis layer is not working.For other shapefiles the search tool works fine.The search query for postgis layer shows the result "The service you called did not return valid XML."
The code for .map file is:
MAP NAME 'livestock' SIZE 800 650 STATUS ON EXTENT 8558119.00 956287.69 8558151.00 956310.56
UNITS METERSINCLUDE "../../geomoose_globals.map"WEB METADATA 'ows_title' 'AHD Centres' 'ows_srs' 'EPSG:26915 EPSG:4326 EPSG:900913 EPSG:3857' 'ows_enable_request' '*' 'ows_onlineresource' 'http://www.geomoose.org' ENDENDPROJECTION 'init=epsg:3857'ENDLAYER NAME 'Field Points' CONNECTIONTYPE postgis CONNECTION "host=My_hostname dbname=My_dbname user=My_username password=My_password port=My_port" DATA "geom1 from details" STATUS ON TYPE POINT TOLERANCE 1 TOLERANCEUNITS METERS LABELITEM "ogc_fid" CLASS NAME 'Field Points' COLOR 0 0 0 OUTLINECOLOR 0 0 0 STYLE SYMBOL 'CIRCLE' SIZE 10 OUTLINECOLOR 204 0 51 COLOR 0 0 0 END LABEL TYPE BITMAP SIZE TINY COLOR 255 255 0 MINDISTANCE 200 PARTIALS TRUE END #end of LABEL END METADATA 'select_record' 'templates/select_result3.html' 'select_header' 'templates/select_header.html' 'identify_record' 'identifyphp6.html' 'itemquery' 'templates/search_result.html' 'itemquery-filter' '/.*[qstring].*/i' 'qstring_validation_pattern' '.' ENDENDEND ## end Map
The code for select_result3.html is as follows:
Id:[ogc_fid]Farmer Name:[name]Uploaded Time:[time]The code for select.php is as follows:
project($shape_projection, $LATLONG_PROJ);if($DEBUG) { error_log('selection shape before buffer: '.$selectShape->toWkt());}# buffer the shape, $selectShape = saneBuffer($selectShape, NULL, $selection_buffer);if($DEBUG) { error_log('Selection buffer: '.$selection_buffer); error_log('wgs84 Selection Shape: '.$selectShape->toWkt());}# $queryShapes is our global bucket for shapes against which we are# going to query the selected layer.$queryShapes = array();# Add the initial selection shape to the query shapes array$queryShapes[] = $selectShape;# If we have a query layer from which to pull shapes, we'll do that.if(isset($queryLayer) and $queryLayer != null and $queryLayer != '') { $queryMap = getMapfile($mapbook, $queryLayer); $layer = array_reverse(explode('/', $queryLayer)); $layer = $layer[0]; $shapeLayersToQuery = array(); # open the map. $map = ms_newMapObj($CONFIGURATION['root'].$queryMap); # get it's projection. $map_proj = $map->getProjection(); # turn it into a real projection object if it's not null. if($map_proj != NULL) { $map_proj = ms_newprojectionobj($map_proj); } # Open the layers. if($layer == 'all') { for($i = 0; $i numlayers; $i++) { array_push($shapeLayersToQuery, $map->getLayer($i)); } } else { array_push($shapeLayersToQuery, $map->getLayerByName($layer)); } for($i = 0; $i getProjection() != NULL) { $layer_projection = ms_newprojectionobj($shapeLayersToQuery[$i]->getProjection()); } # use WKT to create a copy of the shape object (which is in wgs84) if($DEBUG) { error_log($selectShape->toWkt()); } $layer_query_shape = ms_shapeObjFromWkt($selectShape->toWkt()); # $layer_query_shape = saneBuffer($layer_query_shape, NULL, $shape_buffer, $DEBUG); # convert it to local coordinates. $layer_query_shape->project($LATLONG_PROJ, $layer_projection); # setup a dummy template so mapscript will query against the layer. $shapeLayersToQuery[$i]->set('template','dummy.html'); # do the query. $shapeLayersToQuery[$i]->open(); $shapeLayersToQuery[$i]->queryByShape($layer_query_shape); $layer = $shapeLayersToQuery[$i]; while($shape = $layer->nextShape()) { # okay, now we normalize these shapes to 4326, I need something normal # just for a second. # add it to our querying stack for later. if($layer_query_shape->intersects($shape) == MS_TRUE or $shape->containsShape($layer_query_shape) == MS_TRUE) { if($layer_projection != NULL) { # convert the shape to wgs84 for internal use. $shape->project($layer_projection, $LATLONG_PROJ); } if($shape_buffer > 0) { $queryShapes[] = saneBuffer($shape, NULL, $shape_buffer, $DEBUG); } else { $queryShapes[] = $shape; } } else { if($DEBUG) { error_log('MISS SHAPE!'); } } } # close the layer up, we're done with it. $shapeLayersToQuery[$i]->close(); }}# Build a massive shape$queryShape = array_pop($queryShapes); # this should be the initial selection area.foreach($queryShapes as $shape) { $queryShape = $queryShape->union($shape);}# Load up the select map.$selectMap = getMapfile($mapbook, $selectLayer);$map = ms_newMapObj($CONFIGURATION['root'].$selectMap);$layersToQuery = array();$layer = array_reverse(explode('/', $selectLayer));$layer = $layer[0];if($layer == 'all') { for($i = 0; $i numlayers; $i++) { array_push($layersToQuery, $map->getLayer($i)); }} else { array_push($layersToQuery, $map->getLayerByName($layer));}$foundShapes = array();$attributes = false;$results = '';for($i = 0; $i numlayers; $i++) { $layer = $map->getLayer($i); $layer->set('status', MS_OFF); # Turn off extraneous layers $layer->set('template', ''); # this should prevent layers from being queried.}$queryShapeWkt = $queryShape->toWkt();foreach($layersToQuery as $layer) { # fresh query shape $q_shape = ms_shapeObjFromWkt($queryShapeWkt); # Use the map, or layer projection if available. $projection = $map->getProjection(); if($layer->getProjection() != NULL) { $projection = $layer->getProjection(); } if($projection != NULL) { # reproject the query shape as available. if($DEBUG) { error_log('Projection: '.$projection); error_log('wgs84 q_shape: '.$q_shape->toWkt()); } $projection = ms_newProjectionObj($projection); $q_shape->project($LATLONG_PROJ, $projection); if($DEBUG) { error_log('Projected Shape: '.$q_shape->toWkt()); } } $layer->set('template', $layer->getMetadata('select_record')); if($layer->getMetadata('select_header')) { $layer->set('header', $layer->getMetadata('select_header')); } if($layer->getMetadata('select_footer')) { $layer->set('footer', $layer->getMetadata('select_footer')); } $layer->set('status', MS_DEFAULT); $layer->open(); # we'll need these for later. $attributes = $layer->getItems(); # query by our nice large, and now localized query shape. if($DEBUG) { error_log('select.php :: q_shape :'.$q_shape->toWkt()); } $layer->queryByShape($q_shape); while($shape = $layer->nextShape()) { # if we have a projection, convert the shape into latlong if($q_shape->intersects($shape) == MS_TRUE or $shape->containsShape($q_shape) == MS_TRUE) { if($projection != NULL) { $shape->project($projection, $LATLONG_PROJ); } $foundShapes[] = $shape; } } if($DEBUG) { error_log('Found shapes: ' . sizeof($foundShapes)); } $results = $results . $map->processquerytemplate(array(), false);/* for($i=0; $igetNumResults() - 1); $i++){ $result=$layer->getResult($i); $myShape=$layer->getShape($result); $foundShapes[] = $myShape; }} */$fields = array();array_push($fields, 'wkt_geometry text');foreach($attributes as $attribute) { array_push($fields, $attribute.' text');}$uniqueId = 'select_'.getmypid().time();$sqlFilename = $tempDirectory.'/'.$uniqueId.'.db';# make a sqlite connectiontry { $sqlite = new PDO('sqlite:'.$sqlFilename);} catch(Exception $e) { echo "Failed to connect!
"; echo $sqlFilename."
"; echo $e->getMessage();}# create the featuers table$sqlite->beginTransaction();$sqlite->exec('create table features ('.implode(',', $fields).')');$sqlite->commit();# Set up a few variables for substitution later$dict = array();$dict['LAYER_TYPE'] = 'POLYGON';$dict['UNIQUEID'] = $uniqueId;$dict['QUERYID'] = $uniqueId;$dict['SHAPEPATH'] = $tempDirectory;$dict['SHAPE_WKT'] = $shape_wkt;$dict['SELECT_LAYER'] = $selectLayer;$dict['QUERY_LAYER'] = $queryLayer;$dict['SHAPE_BUFFER'] = $shape_buffer;$dict['SELECTION_BUFFER'] = $selection_buffer;$dict['SHOW_FOLLOWUP'] = 'block';if($shape_buffer > 0.1) { $dict['SHOW_FOLLOWUP'] = 'none';}$dict['PROJECTION'] = 'epsg:4326'; #$CONFIGURATION['projection'];# Create the shapefileif(sizeof($foundShapes) > 0 and $foundShapes[0]->type == MS_SHAPE_POINT) { $dict['LAYER_TYPE'] = 'POINT';}foreach($foundShapes as $shape) { $recordArray = array(); array_push($recordArray, $shape->toWKT()); foreach($attributes as $attribute) { array_push($recordArray, $shape->values[$attribute]); } $sqlite->beginTransaction(); $insert_sql = "insert into features values ('".implode("','", $recordArray)."')"; $sqlite->exec($insert_sql); if($DEBUG) { error_log($insert_sql); } $sqlite->commit();}$sqlite->beginTransaction();$sqlite->exec('create table selection (wkt_geometry text, area text)');$cursor = $sqlite->prepare("insert into selection values (?,?)");$shape = ''; $shape_type = '';$cursor->bindParam(1, $shape);$cursor->bindParam(2, $shape_type);$shape = $drawnShape; $shape_type = 'DRAWN';$cursor->execute();$shape = $queryShape->toWKT(); $shape_type = 'QUERY';$cursor->execute();$sqlite->commit();# Form the mapfile.$mapfile = implode('', file($CONFIGURATION['highlight_map']));$mapfile = processTemplate($mapfile, $dict);$mapfileOut = fopen($tempDirectory.'/'.$uniqueId.'.map', 'w+');fwrite($mapfileOut, $mapfile);fclose($mapfileOut);# All that work for a dozen lines of output.header('Content-type: application/xml');print "";print "";print "Found Shapes: '.sizeof($foundShapes).'
';print "Query ID: " . $uniqueId.'
';print processTemplate($results, $dict);print "]]>";?>Thanks in advance.
أكثر...
The code for .map file is:
MAP NAME 'livestock' SIZE 800 650 STATUS ON EXTENT 8558119.00 956287.69 8558151.00 956310.56
UNITS METERSINCLUDE "../../geomoose_globals.map"WEB METADATA 'ows_title' 'AHD Centres' 'ows_srs' 'EPSG:26915 EPSG:4326 EPSG:900913 EPSG:3857' 'ows_enable_request' '*' 'ows_onlineresource' 'http://www.geomoose.org' ENDENDPROJECTION 'init=epsg:3857'ENDLAYER NAME 'Field Points' CONNECTIONTYPE postgis CONNECTION "host=My_hostname dbname=My_dbname user=My_username password=My_password port=My_port" DATA "geom1 from details" STATUS ON TYPE POINT TOLERANCE 1 TOLERANCEUNITS METERS LABELITEM "ogc_fid" CLASS NAME 'Field Points' COLOR 0 0 0 OUTLINECOLOR 0 0 0 STYLE SYMBOL 'CIRCLE' SIZE 10 OUTLINECOLOR 204 0 51 COLOR 0 0 0 END LABEL TYPE BITMAP SIZE TINY COLOR 255 255 0 MINDISTANCE 200 PARTIALS TRUE END #end of LABEL END METADATA 'select_record' 'templates/select_result3.html' 'select_header' 'templates/select_header.html' 'identify_record' 'identifyphp6.html' 'itemquery' 'templates/search_result.html' 'itemquery-filter' '/.*[qstring].*/i' 'qstring_validation_pattern' '.' ENDENDEND ## end Map
The code for select_result3.html is as follows:
Id:[ogc_fid]Farmer Name:[name]Uploaded Time:[time]The code for select.php is as follows:
project($shape_projection, $LATLONG_PROJ);if($DEBUG) { error_log('selection shape before buffer: '.$selectShape->toWkt());}# buffer the shape, $selectShape = saneBuffer($selectShape, NULL, $selection_buffer);if($DEBUG) { error_log('Selection buffer: '.$selection_buffer); error_log('wgs84 Selection Shape: '.$selectShape->toWkt());}# $queryShapes is our global bucket for shapes against which we are# going to query the selected layer.$queryShapes = array();# Add the initial selection shape to the query shapes array$queryShapes[] = $selectShape;# If we have a query layer from which to pull shapes, we'll do that.if(isset($queryLayer) and $queryLayer != null and $queryLayer != '') { $queryMap = getMapfile($mapbook, $queryLayer); $layer = array_reverse(explode('/', $queryLayer)); $layer = $layer[0]; $shapeLayersToQuery = array(); # open the map. $map = ms_newMapObj($CONFIGURATION['root'].$queryMap); # get it's projection. $map_proj = $map->getProjection(); # turn it into a real projection object if it's not null. if($map_proj != NULL) { $map_proj = ms_newprojectionobj($map_proj); } # Open the layers. if($layer == 'all') { for($i = 0; $i numlayers; $i++) { array_push($shapeLayersToQuery, $map->getLayer($i)); } } else { array_push($shapeLayersToQuery, $map->getLayerByName($layer)); } for($i = 0; $i getProjection() != NULL) { $layer_projection = ms_newprojectionobj($shapeLayersToQuery[$i]->getProjection()); } # use WKT to create a copy of the shape object (which is in wgs84) if($DEBUG) { error_log($selectShape->toWkt()); } $layer_query_shape = ms_shapeObjFromWkt($selectShape->toWkt()); # $layer_query_shape = saneBuffer($layer_query_shape, NULL, $shape_buffer, $DEBUG); # convert it to local coordinates. $layer_query_shape->project($LATLONG_PROJ, $layer_projection); # setup a dummy template so mapscript will query against the layer. $shapeLayersToQuery[$i]->set('template','dummy.html'); # do the query. $shapeLayersToQuery[$i]->open(); $shapeLayersToQuery[$i]->queryByShape($layer_query_shape); $layer = $shapeLayersToQuery[$i]; while($shape = $layer->nextShape()) { # okay, now we normalize these shapes to 4326, I need something normal # just for a second. # add it to our querying stack for later. if($layer_query_shape->intersects($shape) == MS_TRUE or $shape->containsShape($layer_query_shape) == MS_TRUE) { if($layer_projection != NULL) { # convert the shape to wgs84 for internal use. $shape->project($layer_projection, $LATLONG_PROJ); } if($shape_buffer > 0) { $queryShapes[] = saneBuffer($shape, NULL, $shape_buffer, $DEBUG); } else { $queryShapes[] = $shape; } } else { if($DEBUG) { error_log('MISS SHAPE!'); } } } # close the layer up, we're done with it. $shapeLayersToQuery[$i]->close(); }}# Build a massive shape$queryShape = array_pop($queryShapes); # this should be the initial selection area.foreach($queryShapes as $shape) { $queryShape = $queryShape->union($shape);}# Load up the select map.$selectMap = getMapfile($mapbook, $selectLayer);$map = ms_newMapObj($CONFIGURATION['root'].$selectMap);$layersToQuery = array();$layer = array_reverse(explode('/', $selectLayer));$layer = $layer[0];if($layer == 'all') { for($i = 0; $i numlayers; $i++) { array_push($layersToQuery, $map->getLayer($i)); }} else { array_push($layersToQuery, $map->getLayerByName($layer));}$foundShapes = array();$attributes = false;$results = '';for($i = 0; $i numlayers; $i++) { $layer = $map->getLayer($i); $layer->set('status', MS_OFF); # Turn off extraneous layers $layer->set('template', ''); # this should prevent layers from being queried.}$queryShapeWkt = $queryShape->toWkt();foreach($layersToQuery as $layer) { # fresh query shape $q_shape = ms_shapeObjFromWkt($queryShapeWkt); # Use the map, or layer projection if available. $projection = $map->getProjection(); if($layer->getProjection() != NULL) { $projection = $layer->getProjection(); } if($projection != NULL) { # reproject the query shape as available. if($DEBUG) { error_log('Projection: '.$projection); error_log('wgs84 q_shape: '.$q_shape->toWkt()); } $projection = ms_newProjectionObj($projection); $q_shape->project($LATLONG_PROJ, $projection); if($DEBUG) { error_log('Projected Shape: '.$q_shape->toWkt()); } } $layer->set('template', $layer->getMetadata('select_record')); if($layer->getMetadata('select_header')) { $layer->set('header', $layer->getMetadata('select_header')); } if($layer->getMetadata('select_footer')) { $layer->set('footer', $layer->getMetadata('select_footer')); } $layer->set('status', MS_DEFAULT); $layer->open(); # we'll need these for later. $attributes = $layer->getItems(); # query by our nice large, and now localized query shape. if($DEBUG) { error_log('select.php :: q_shape :'.$q_shape->toWkt()); } $layer->queryByShape($q_shape); while($shape = $layer->nextShape()) { # if we have a projection, convert the shape into latlong if($q_shape->intersects($shape) == MS_TRUE or $shape->containsShape($q_shape) == MS_TRUE) { if($projection != NULL) { $shape->project($projection, $LATLONG_PROJ); } $foundShapes[] = $shape; } } if($DEBUG) { error_log('Found shapes: ' . sizeof($foundShapes)); } $results = $results . $map->processquerytemplate(array(), false);/* for($i=0; $igetNumResults() - 1); $i++){ $result=$layer->getResult($i); $myShape=$layer->getShape($result); $foundShapes[] = $myShape; }} */$fields = array();array_push($fields, 'wkt_geometry text');foreach($attributes as $attribute) { array_push($fields, $attribute.' text');}$uniqueId = 'select_'.getmypid().time();$sqlFilename = $tempDirectory.'/'.$uniqueId.'.db';# make a sqlite connectiontry { $sqlite = new PDO('sqlite:'.$sqlFilename);} catch(Exception $e) { echo "Failed to connect!
"; echo $sqlFilename."
"; echo $e->getMessage();}# create the featuers table$sqlite->beginTransaction();$sqlite->exec('create table features ('.implode(',', $fields).')');$sqlite->commit();# Set up a few variables for substitution later$dict = array();$dict['LAYER_TYPE'] = 'POLYGON';$dict['UNIQUEID'] = $uniqueId;$dict['QUERYID'] = $uniqueId;$dict['SHAPEPATH'] = $tempDirectory;$dict['SHAPE_WKT'] = $shape_wkt;$dict['SELECT_LAYER'] = $selectLayer;$dict['QUERY_LAYER'] = $queryLayer;$dict['SHAPE_BUFFER'] = $shape_buffer;$dict['SELECTION_BUFFER'] = $selection_buffer;$dict['SHOW_FOLLOWUP'] = 'block';if($shape_buffer > 0.1) { $dict['SHOW_FOLLOWUP'] = 'none';}$dict['PROJECTION'] = 'epsg:4326'; #$CONFIGURATION['projection'];# Create the shapefileif(sizeof($foundShapes) > 0 and $foundShapes[0]->type == MS_SHAPE_POINT) { $dict['LAYER_TYPE'] = 'POINT';}foreach($foundShapes as $shape) { $recordArray = array(); array_push($recordArray, $shape->toWKT()); foreach($attributes as $attribute) { array_push($recordArray, $shape->values[$attribute]); } $sqlite->beginTransaction(); $insert_sql = "insert into features values ('".implode("','", $recordArray)."')"; $sqlite->exec($insert_sql); if($DEBUG) { error_log($insert_sql); } $sqlite->commit();}$sqlite->beginTransaction();$sqlite->exec('create table selection (wkt_geometry text, area text)');$cursor = $sqlite->prepare("insert into selection values (?,?)");$shape = ''; $shape_type = '';$cursor->bindParam(1, $shape);$cursor->bindParam(2, $shape_type);$shape = $drawnShape; $shape_type = 'DRAWN';$cursor->execute();$shape = $queryShape->toWKT(); $shape_type = 'QUERY';$cursor->execute();$sqlite->commit();# Form the mapfile.$mapfile = implode('', file($CONFIGURATION['highlight_map']));$mapfile = processTemplate($mapfile, $dict);$mapfileOut = fopen($tempDirectory.'/'.$uniqueId.'.map', 'w+');fwrite($mapfileOut, $mapfile);fclose($mapfileOut);# All that work for a dozen lines of output.header('Content-type: application/xml');print "";print "";print "Found Shapes: '.sizeof($foundShapes).'
';print "Query ID: " . $uniqueId.'
';print processTemplate($results, $dict);print "]]>";?>Thanks in advance.
أكثر...