4.10 GEOS Fuctions with PHP Mapscipt

CamKhmer chrisscrazydays at HOTMAIL.COM
Thu Oct 26 22:52:24 EDT 2006


Hi Yewondwossen,

Thanks for your feedback, as you said districts are within provinces. I
tried switching the statement and running it through an if statement like
so:

if($oDistShape->within($oProvShape)) {
      echo "true";
}
else {
      echo "false";
}

This just returned false on every attempt as the argument isn't recieving
any value, true or false. I really don't think this is a syntax issue. The
method just won't return a result if the shapes are from serperate shape
files, is this how it is supposed to work or is this an issue with the
Mapscript implimention?

Regards,

Chris


Yewondwossen Assefa wrote:
> 
> Chris,
> 
>   The within function returns true or false so tests should be done like 
> this if ($oProvShape->within($oDistShape)) echo "1" else echo "0".  The 
> blank page in your case simple means that the within function returned 
> false.
> 
>   Is it possible that the test you are doing is inversed? : by looking 
> at the name of the layers, I am assuming that districts are inside 
> provinces so a call $oProvShape->within($oDistShape) would return false 
> and the $oDistShape->within($oProvShape); would return true.
> 
>   I have checked the documentation of php mapscript and it was stated 
> incorrectly leading to the confusion. It is now updated and reflects the 
> correct syntax.
> 
>   Let me know if that solves your problem.
> 
> Best Regards,
> 
> CamKhmer wrote:
>> 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.
>>>
>>>
>> 
>> 
> 
> 
> -- 
> ----------------------------------------------------------------
> Assefa Yewondwossen
> Software Analyst
> 
> Email: assefa at dmsolutions.ca
> http://www.dmsolutions.ca/
> 
> Phone: (613) 565-5056 (ext 14)
> Fax:   (613) 565-0925
> ----------------------------------------------------------------
> 
> 

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



More information about the mapserver-users mailing list