Opened 18 years ago

Closed 18 years ago

#1623 closed defect (duplicate)

[PHP] Add Geos function : Contains

Reported by: assefa Owned by: jmckenna@…
Priority: high Milestone:
Component: MapScript-PHP Version: 4.8
Severity: normal Keywords:
Cc: mapserver@…

Description

Add geos function contains  (see also Bug 1327). Here is an e-mail from Steve 
explaining how it works :

 For grins I added the conains operator to the geos wrapper and to Swig-based
mapscript. That support is in CVS head (not 4.8, too late for that, sorry).
I hesitate to touch the PHP wrapper though. You'll have to convince one of
the other developers to make that change (or have them ok me doing it).

Anyway in a language like Perl you can do:

shape1 = mapscript::shapeObj::fromWKT('POLYGON((0.0 0.0, 0.0 2.0, 2.0 2.0,
2.0 0.0, 0.0 0.0))') or die("Shape 1: ". mapscript::msGetErrorString("\n")
."\n");
$shape2 = mapscript::shapeObj::fromWKT('POLYGON((0.5 0.5,0.5 1.5,1.5 1.5,1.5
0.5,0.5 0.5))') or die("Shape 2:". mapscript::msGetErrorString("\n") ."\n");

print $shape1->contains($shape2) ."\n";
print $shape2->contains($shape1) ."\n";
print $shape2->contains($shape2) ."\n";

Which outputs:

1
0
1

as expected. This is only exposing the operator. Nothing is itegrated into
the MapServer query functions. However, in MapScript you could:

1) use the bounds of shape 1 to do a rect-based query and then
2) loop through the result set doing contains

I'm not going to do a full implementation of GEOS until I convert the cpp
interface to c (sometime soon). However, it seems like contains might be
interesting to folks in the meantime so...

Change History (6)

comment:1 by assefa, 18 years ago

Cc: mapserver-bugs@… added
Owner: changed from mapserverbugs to assefa
looking into this

comment:2 by assefa, 18 years ago

Owner: changed from assefa to jmckenna@…
Added function containsShape. README is updated. 

Here is an example of usage :

 <?php

dl("php_mapscript_48.dll");


$shape1 =  ms_shapeObjFromWkt("POLYGON((0.0 0.0, 0.0 2.0, 2.0 2.0, 2.0 0.0, 
0.0 0.0))");

$shape2 =  ms_shapeObjFromWkt("POLYGON((0.5 0.5, 0.5 1.5, 1.5 1.5, 1.5 0.5, 
0.5 0.5))");

if ($shape1->containsShape($shape2))
     echo "1\n";
 else
  echo "0\n";

if ($shape2->containsShape($shape1))
 echo "1\n";
 else
  echo "0\n";

if ($shape2->containsShape($shape2))
 echo "1\n";
 else
  echo "0\n"; 

?>

 It would be nice if these small examples made it to the documetation somehow. 

 Reassigned to Jeff.

comment:3 by dmorissette, 18 years ago

Assefa, your code example loads php_mapscritp_48.dll, but hopefully you added
this only to 4.9 and not to 4.8? Steve wrote: "not in 4.8, too late for that,
sorry", so we should add this only to the same versions that are supported by
the SWIG MapScript.

comment:4 by assefa, 18 years ago

I only added it to the CVS head.

comment:5 by mapserver@…, 18 years ago

Cc: mapserver@… added

comment:6 by assefa, 18 years ago

Resolution: duplicate
Status: newclosed

*** This bug has been marked as a duplicate of 1327 ***
Note: See TracTickets for help on using tickets.