4.10 GEOS Fuctions with PHP Mapscipt

CamKhmer chrisscrazydays at HOTMAIL.COM
Wed Oct 25 18:25:04 PDT 2006


Hi Steve,

Thanks for your response. I am not receiving the response I was expecting
from the shapeObj->within() method when I pass to it a shapeObj from a
separate layer. I was expecting that GEOS would compare the geometry of
shape A and shape B then determine whether one was within the other, if this
was the case I thought that this method could take any valid shape object
regardless of its source, but this appears not to be the case. Here's a
thinned down version of what I'm trying to do (apologies for posting an
elongated chunk of code up):

<?php
$oMap = ms_newMapObj($szMapFile);

function getShapeByName($oMap, $sLayerName, $sColumnName, $sShapeName){
	$oLayer = $oMap->getLayerByName($sLayerName);
	$oLayer->open();

	//returns all the shapes in the layer
	$status = $oLayer->whichShapes($oMap->extent);

	//Loop through each of the shapes
	while ($shape = $oLayer->nextShape()) 
		   {
			   $shapeIndex = $shape->index;
			   $oShape = $oLayer->getShape(-1,$shapeIndex);
			   $sName = $oShape->values[$sColumnName];

			   //return if we have the shape we're after
			   if($sName == $sShapeName) {
			   		return $oShape;
			   }		   		   
		   }
	return null; 	   
	//$oLayer->close();	
}

//Get the province shape obj
$oProvShape = getShapeByName($oMap, 'provinces_fill', 'NAME','KHAMMUANE');

//Get the district shape obj
$oDistShape = getShapeByName($oMap, 'districts', 'NAME', 'NAKAI');

//This shows I have the shape object so we know there are no problems prior
to this
print_r($oProvShape);
print_r($oDistShape);

//See if one shape is within another
$inside = $oProvShape->within($oDistShape);

//Should return true or false
echo $inside;
?>

The above code just returns a blank screen, if I replace:

$inside = $oProvShape->within($oDistShape);

with:

$inside = $oProvShape->within($oProvShape);

It returns 1 as expected, which indicated to me that shape objects from one
shape file can't be passed as an argument for the within() method of a shape
object from a different shape file. Is this the case? If so is there any
work around you can think of that doesn't involve dumping all the layers in
a single shape file.

Thanks for any input you can give me.

Chris



Steve Lime wrote:
> 
> Chris: The GEOS operators work at the shapeObj level and have no
> connection to 
> parent layers (you can create shapeObj's without mapfiles).
> 
> Are you seeing strange behavior?
> 
> Steve
> 
>>>> CamKhmer <chrisscrazydays at HOTMAIL.COM> 10/24/2006 7:27:14 AM >>>
> Hi Guys,
> 
> I have just begun experimenting with the GEOS functions now available in
> 4.10 via mapscript and have a question.
> 
> Can shape objects from layer object A be passed as arguments to shape
> object
> methods in layer object B? (Each layer has a separate shape file)
> 
> I am trying to create a function that determines if shape A (district) is
> within shape B (province), as stated above both layers are separate layers
> in separate shape files.
> 
> I know I have the objects needed as both can be output using print_r(), I
> know the method is working as if I pass a shape object from the same layer
> I
> get the results as expected.
> 
> Is it just the case that shape objects from different layers or shape
> files
> can’t be passed as objects to shapeObj methods? If so it there any
> feasible
> way around this or am I just going to have to put both districts and
> provinces in the same layer and output them through class references?
> 
> Thanks for your ideas,
> 
> Chris
> 
> -- 
> View this message in context:
> http://www.nabble.com/4.10-GEOS-Fuctions-with-PHP-Mapscipt-tf2500940.html#a6971770 
> Sent from the Mapserver - User mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context: http://www.nabble.com/4.10-GEOS-Fuctions-with-PHP-Mapscipt-tf2500940.html#a7003645
Sent from the Mapserver - User mailing list archive at Nabble.com.



More information about the MapServer-users mailing list