[mapguide-users] RE: RE: Wish List
Jim O'Leary
joleary.public at gmail.com
Sat Apr 14 19:01:01 EDT 2007
Here's another PHP solution. Make a MgCoordinateSystemTransform object and
use it with the
Transform() method of the geometry object that you get from
$featureReader->ReadNext().
In this case I'm transforming whatever the map's SRS is into BC Albers,
which is metric.
$BCALBERS =
'PROJCS["BC_Albers",GEOGCS["LL83",DATUM["NAD83",SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["false_easting",1000000.000],PARAMETER["false_northing",0.000],PARAMETER["standard_parallel_1",58.50000000000000],PARAMETER["standard_parallel_2",50.00000000000000],PARAMETER["latitude_of_origin",45.00000000000000],PARAMETER["central_meridian",-126.00000000000000],UNIT["Meter",1.00000000000000]]';
$coordSysFactory = new MgCoordinateSystemFactory();
// Assuming you have opened the map...
$source = $coordSysFactory->Create($map->GetMapSRS());
$target = $coordSysFactory->Create($BCALBERS);
$transform = new MgCoordinateSystemTransform($source, $target);
// make the feature reader, and then...
while ($featureReader->ReadNext())
{
$byteReader = $featureReader->GetGeometry('GEOMETRY');
$geometryReaderWriter = new MgAgfReaderWriter();
$geometry = $geometryReaderWriter->Read($byteReader);
// Transform to BC Albers
$geometry = $geometry->Transform($transform);
$area = $geometry->GetArea();
}// end while
With further tests, you could determine if your geometry is a line or
linestring, and extract the length
instead of the area with $geometry->GetLength()
Kori Maleski-3 wrote:
>
> Here is how to get area with a coordinate transform:
>
>
>
> Say - if my map is projected, but my data is in Latlong.
>
>
>
>
>
>
>
> If l_ofeatures.ReadNext() Then
>
>
>
> Do
>
>
>
> Dim l_oMgByteReader As MgByteReader =
> l_ofeatures.GetGeometry("Geometry")
>
> Dim l_oGeometryReaderWriter As New MgAgfReaderWriter
>
> Dim l_oMgGeometry As MgGeometry =
> l_oGeometryReaderWriter.Read(l_oMgByteReader)
>
> Dim l_oMgPolygon As MgPolygon = l_oMgGeometry
>
>
>
>
>
> 'Get Current map projection
>
> Dim l_sWKTproj As String = p_oMap.GetMapSRS()
>
> 'Create Coordinate System object to Reproject
>
> Dim l_oMGCoordinateSystemDestination As
> MgCoordinateSystem = l_oMGCoordinateSystemFactory.Create(l_sWKTproj)
>
>
>
> Dim l_sWKTproj As String =
> "GEOGCS[LL84,DATUM[WGS84,SPHEROID[WGS84,6378137.000,298.25722293]],PRIMEM[Gr
> eenwich,0],UNIT[Degree,0.01745329251994]]"
>
> Dim l_oMGCoordinateSystemSource As MgCoordinateSystem
> =
> l_oMGCoordinateSystemFactory.Create(l_sWKTproj)
>
>
>
> Dim l_oMGTransform As MgTransform
>
> l_oMGTransform = New
> MgCoordinateSystemTransform(l_oMGCoordinateSystemSource,
> l_oMGCoordinateSystemDestination)
>
> l_oMgPolygon.Transform(l_oMGTransform)
>
> Dim l_dArea As Double = l_oMgPolygon.Area
>
>
>
> Loop While l_ofeatures.ReadNext()
>
>
>
> End If
>
>
>
> l_ofeatures.Close()
>
>
>
>
>
>
>
> a'la PHP flavour:
>
>
>
>
>
> function GetTransform()
>
> {
>
> $coordSysFactory = new MgCoordinateSystemFactory();
>
> $resourceService =
> $this->site->CreateService(MgServiceType::ResourceService);
>
>
>
> $map = new MgMap();
>
> $map->Open($resourceService, $this->args['MAPNAME']);
>
>
>
> $source =
> $coordSysFactory->Create("GEOGCS[LL84,DATUM[WGS84,SPHEROID[WGS84,6378137.000
> ,298.25722293]],PRIMEM[Greenwich,0],UNIT[Degree,0.01745329251994]]");
>
> $target = $coordSysFactory->Create($map->GetMapSRS());
>
>
>
>
>
> return new MgCoordinateSystemTransform($source, $target);
>
> }
>
>
>
>
>
>
>
>
>
> ________________________________
>
>
>
>
>
>
>
>
>
> Kori Maleski
>
> Senior Application Developer
>
> WEBSOFT DEVELOPERS, INC.
>
> P: (530) 759-8754 ext 114
>
> F: (530) 759-0923
>
> kori.maleski at websoftdev.com
>
> ________________________________
>
>
>
>
>
> -----Original Message-----
> From: mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Jason Birch
> Sent: Tuesday, April 10, 2007 2:24 PM
> To: MapGuide Users Mail List
> Subject: RE: [mapguide-users] RE: Wish List
>
>
>
> Hi Jim,
>
>
>
> That's giving you the area in degrees, which is a nonsense number.
>
>
>
> You need to transform your LL geometry into a projected system like UTM
>
> (or maybe BC Albers for your application?).
>
>
>
> Jason
>
>
>
> -----Original Message-----
>
> From: Jim O'Leary
>
> Subject: [mapguide-users] RE: Wish List
>
>
>
> However, the number that I get is:
>
>
>
> 0.00022107919307102
>
>
>
> which does not seem meaningful.
>
> _______________________________________________
>
> mapguide-users mailing list
>
> mapguide-users at lists.osgeo.org
>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
--
View this message in context: http://www.nabble.com/Wish-List-tf2473397s16610.html#a9997990
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list