[Mapserver-users] how to use projection object with php mapscript
Stephen Clark
stephen.clark at focus.ca
Thu Feb 19 16:44:52 PST 2004
This is a multi-part message in MIME format.
------=_NextPart_000_08AD_01C3F707.B21EF1B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all,
I am working on a queryByPoint(...) application that lookups up a point =
in a polygon and retrieves the polygon key
code:
$query_type =3D MS_SINGLE;
$query_buffer =3D 0;
$my_PointObj =3D ms_newPointObj();
$my_PointObj->setXY($eastingValue,$northingValue );
@$retval =3D $layer->queryByPoint($my_PointObj, $query_type , =
$query_buffer);
print " Layer processed is : $layer_name <br>";
if ($retval =3D=3D MS_SUCCESS)
{
print " <br> SUCCESSFULLY found layer : $layer_name <br>";
// get the number of results
$numResults =3D $layer->getNumResults();
print " number of results IN LAYER is : $numResults <br>";
// get the shape index
$shapeIndex =3D $layer->index;
print " the LAYER shapeIndex is : $shapeIndex <br>";
// get the shape object
$my_ShapeObj =3D ms_newShapeObj(MS_SHAPE_POLYGON);
// get the shape object numvalues
print " the ShapeObj numvalues after create is : $my_ShapeObj->numvalues =
<br>";
$retval =3D $layer->open();
$my_ShapeObj =3D $layer->getShape(-1, $shapeIndex );
// get the shape object numvalues
print " the ShapeObj numvalues is : $my_ShapeObj->numvalues <br>";
--- > here the number of shape objects is 2 -- should it not be one < =
---
// get the shape object bounding box
$my_RectObj =3D ms_newRectObj();
$my_RectObj =3D $my_ShapeObj->bounds;
print " the ShapeObj bounding box -- minX value is : $my_RectObj->minx =
<br>";
print " the ShapeObj bounding box -- minY value is : $my_RectObj->miny =
<br>";
print " the ShapeObj bounding box -- maxX value is : $my_RectObj->maxx =
<br>";
print " the ShapeObj bounding box -- maxY value is : $my_RectObj->maxy =
<br>";
// get the shape object text string
print " the ShapeObj text string is : $my_ShapeObj->text <br>";
// test to see if the easting / northing point is inside the shape =
object
$retval =3D $my_ShapeObj->contains($my_PointObj);
if ( $retval =3D=3D MS_TRUE)
{
print " the ShapeObj contains the point object <br>";=20
}
if ( $retval =3D=3D MS_FALSE)
{
print " the ShapeObj DOES NOT contains the point object <br>";=20
--> Because there are two Shape Objects, I believe there might be a =
problem here < --
}
// get the key in the shape file
$gridKey =3D $my_ShapeObj->values["GRIDKEY"];=20
print " The grid key is : $gridKey <br>";
Problem :
The bounding box of the shape object is not anywhere close to the point =
coordinates I select. (Roughly 6 km in easting by 24 km in Northing near =
55 degrees latitude and 23km in easting by 38 km inn northing near 60 =
degrees latitude)
I am using UTM coordinates on Zone 10 Nad 83.
I have thought of using the point-> project(...) function but all my =
coords I use are in the same projection.
Here is what I have though:
$my_PointObj =3D ms_newPointObj();
$my_PointObj->setXY($eastingValue,$northingValue );
$projInObj =3D =
ms_newprojectionobj("proj=3Dutm,ellps=3DGRS80,zone=3D10,north,no_defs");
$projOutObj =3D =
ms_newprojectionobj("proj=3Dutm,ellps=3DGRS80,zone=3D10,north,no_defs");
$retval =3D $my_PointObj->project( $projInObj, $projOutObj );
print " The PointObj - > X after projection is : $my_PointObj->x <br>";
print " The PointObj - > Y after projection is : $my_PointObj->y <br>";
any thoughts,
Stephen
------=_NextPart_000_08AD_01C3F707.B21EF1B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I am working on a queryByPoint(...)=20
application that lookups up a point in a polygon and retrieves the =
polygon=20
key</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>
<P><FONT face=3DArial size=3D2>$query_type =3D MS_SINGLE;</FONT></P>
<P><FONT face=3DArial size=3D2>$query_buffer =3D 0;</FONT></P></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>$my_PointObj =3D =
ms_newPointObj();</FONT></P>
<P><FONT face=3DArial =
size=3D2>$my_PointObj->setXY($eastingValue,$northingValue=20
);</FONT></P></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>@$retval =3D =
$layer->queryByPoint($my_PointObj,=20
$query_type , $query_buffer);</FONT></P>
<P><FONT face=3DArial size=3D2>print " Layer processed is : $layer_name=20
<br>";</FONT></P>
<P><FONT face=3DArial size=3D2>if ($retval =3D=3D MS_SUCCESS)</FONT></P>
<P><FONT face=3DArial size=3D2>{</FONT></P>
<P><FONT face=3DArial size=3D2>print " <br> SUCCESSFULLY found =
layer :=20
$layer_name <br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the number of results</FONT></P>
<P><FONT face=3DArial size=3D2>$numResults =3D =
$layer->getNumResults();</FONT></P>
<P><FONT face=3DArial size=3D2>print " number of results IN LAYER is : =
$numResults=20
<br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape index</FONT></P>
<P><FONT face=3DArial size=3D2>$shapeIndex =3D =
$layer->index;</FONT></P>
<P><FONT face=3DArial size=3D2>print " the LAYER shapeIndex is : =
$shapeIndex=20
<br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape object</FONT></P>
<P><FONT face=3DArial size=3D2>$my_ShapeObj =3D=20
ms_newShapeObj(MS_SHAPE_POLYGON);</FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape object =
numvalues</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj numvalues after =
create is :=20
$my_ShapeObj->numvalues <br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>$retval =3D $layer->open();</FONT></P>
<P><FONT face=3DArial size=3D2>$my_ShapeObj =3D $layer->getShape(-1, =
$shapeIndex=20
);</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape object =
numvalues</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj numvalues is :=20
$my_ShapeObj->numvalues <br>";</FONT></P>
<P><FONT face=3DArial><STRONG>--- > here the number of shape objects =
is 2 --=20
should it not be one < ---</STRONG></FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape object bounding =
box</FONT></P>
<P><FONT face=3DArial size=3D2>$my_RectObj =3D =
ms_newRectObj();</FONT></P>
<P><FONT face=3DArial size=3D2>$my_RectObj =3D =
$my_ShapeObj->bounds;</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj bounding box -- minX =
value is :=20
$my_RectObj->minx <br>";</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj bounding box -- minY =
value is :=20
$my_RectObj->miny <br>";</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj bounding box -- maxX =
value is :=20
$my_RectObj->maxx <br>";</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj bounding box -- maxY =
value is :=20
$my_RectObj->maxy <br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the shape object text =
string</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj text string is :=20
$my_ShapeObj->text <br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// test to see if the easting / northing =
point is=20
inside the shape object</FONT></P>
<P><FONT face=3DArial size=3D2>$retval =3D=20
$my_ShapeObj->contains($my_PointObj);</FONT></P>
<P><FONT face=3DArial size=3D2>if ( $retval =3D=3D MS_TRUE)</FONT></P>
<P><FONT face=3DArial size=3D2>{</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj contains the point =
object=20
<br>"; </FONT></P>
<P><FONT face=3DArial size=3D2>}</FONT></P>
<P><FONT face=3DArial size=3D2>if ( $retval =3D=3D MS_FALSE)</FONT></P>
<P><FONT face=3DArial size=3D2>{</FONT></P>
<P><FONT face=3DArial size=3D2>print " the ShapeObj DOES NOT contains =
the point=20
object <br>"; </FONT></P>
<P><FONT face=3DArial><STRONG>--> Because there are two Shape =
Objects, I=20
believe there might be a problem here < =
--</STRONG></FONT></P>
<P><FONT face=3DArial size=3D2>}</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>// get the key in the shape =
file</FONT></P>
<P><FONT face=3DArial size=3D2>$gridKey =3D =
$my_ShapeObj->values["GRIDKEY"];=20
</FONT></P>
<P><FONT face=3DArial size=3D2>print " The grid key is : $gridKey=20
<br>";</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2></FONT> </P>
<P><FONT face=3DArial size=3D2>Problem :</FONT></P>
<P><FONT face=3DArial size=3D2>The bounding box of the shape object is =
not anywhere=20
close to the point coordinates I select. (Roughly 6 km in easting by 24 =
km in=20
Northing near 55 degrees latitude and 23km in easting by 38 km inn =
northing near=20
60 degrees latitude)</FONT></P>
<P><FONT face=3DArial size=3D2>I am using UTM coordinates on Zone 10 Nad =
83.</FONT></P>
<P><FONT face=3DArial size=3D2>I have thought of using the point-> =
project(...)=20
function but all my coords I use are in the same projection.</FONT></P>
<P><FONT face=3DArial size=3D2>Here is what I have =
though:</FONT></P><FONT=20
face=3DArial size=3D2><FONT size=3D2>
<P>$my_PointObj =3D ms_newPointObj();</P>
<P>$my_PointObj->setXY($eastingValue,$northingValue );</P><FONT =
size=3D2>
<P>$projInObj =3D=20
ms_newprojectionobj("proj=3Dutm,ellps=3DGRS80,zone=3D10,north,no_defs");<=
/P>
<P>$projOutObj =3D=20
ms_newprojectionobj("proj=3Dutm,ellps=3DGRS80,zone=3D10,north,no_defs");<=
/P>
<P>$retval =3D $my_PointObj->project( $projInObj, $projOutObj );</P>
<P>print " The PointObj - > X after projection is : =
$my_PointObj->x=20
<br>";</P>
<P>print " The PointObj - > Y after projection is : =
$my_PointObj->y=20
<br>";</P>
<P> </P>
<P>any thoughts,</P>
<P>Stephen</P>
<P> </P></FONT></FONT></FONT></DIV></BODY></HTML>
------=_NextPart_000_08AD_01C3F707.B21EF1B0--
More information about the MapServer-users
mailing list