[mapguide-commits] r4217 - in trunk/MgDev/Common: CoordinateSystem Geometry/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Sep 10 15:04:39 EDT 2009


Author: NormOlsen
Date: 2009-09-10 15:04:39 -0400 (Thu, 10 Sep 2009)
New Revision: 4217

Modified:
   trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemFactory.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h
Log:
This submission can be considered the first complete beta submission for RFC 76.  It includes all (most all anyway) functionality originally intended by the RFC, and most all functionality has been tested, superficially, in a rather sterile environment using only the debugger to manually inspect numerical results.  Surely, once a real application produces graphical results we will have some bugs to fix.

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-09-10 19:04:39 UTC (rev 4217)
@@ -529,6 +529,10 @@
     MG_CATCH_AND_THROW(L"MgCoordinateSystemGridBoundary.GetBoundaryExtents")
     return;
 }
+void CCoordinateSystemGridBoundary::SetMaxCurvePoints (INT32 maxPoints)
+{
+    m_MaxCurvePoints = maxPoints;
+}
 // The Polygon returned by this function will not (usually) be a simple
 // rectangle, but a series of complex curves which (usually) approximate
 // a trapazoid.
@@ -726,22 +730,121 @@
 // CCoordinateSystemGridRegion -- Associates a label/designation with a
 //                                MgPolygon object.
 //
-CCoordinateSystemGridRegion::CCoordinateSystemGridRegion (STRING label,MgPolygon* polygon)
-                                    :
-                                MgCoordinateSystemGridRegion (),
-                                m_RegionLabel                (label),
-                                m_Polygon                    ()
+CCoordinateSystemGridRegion::CCoordinateSystemGridRegion (STRING label,
+                                                          MgCoordinateSystemGridBoundary* frameBoundary,
+                                                          MgCoordinateSystemTransform* gridToFrame,
+                                                          MgCoordinate* southwest,
+                                                          MgCoordinate* northeast,
+                                                          double curvePrecision,
+                                                          INT32 maxPoints)
+                                                               :
+                                                          MgCoordinateSystemGridRegion (),
+                                                          m_RegionLabel                (label),
+                                                          m_RegionCenter               (),
+                                                          m_RegionBoundary             (),
+                                                          m_SouthLine                  (),
+                                                          m_EastLine                   (),
+                                                          m_NorthLine                  (),
+                                                          m_WestLine                   ()
 {
-    m_Polygon = SAFE_ADDREF (polygon);
-}                                
+    double xx, yy;
+    double southLimit;
+    double northLimit;
+    double eastLimit;
+    double westLimit;
+
+    Ptr<MgCoordinate> southeast;
+    Ptr<MgCoordinate> northwest;
+    Ptr<MgCoordinate> centerPoint;
+    Ptr<MgLineString> lineString;
+    Ptr<MgCoordinateSystemGridBoundary> regionBoundaryInGridCrs;
+
+    MgGeometryFactory mgFactory;
+    MgCoordinateSystemFactory csFactory;
+
+    MG_TRY()
+        // Get the region limits in a convenient form.
+        westLimit = southwest->GetX ();
+        eastLimit = northeast->GetX ();
+        southLimit = southwest->GetY ();
+        northLimit = northeast->GetY ();
+        southeast = mgFactory.CreateCoordinateXY (eastLimit,southLimit);
+        northwest = mgFactory.CreateCoordinateXY (westLimit,northLimit);
+
+        // Calculate the center of the region and convert to frame coordinates.
+        xx = 0.5 * (eastLimit  + westLimit);
+        yy = 0.5 * (northLimit + southLimit);
+        gridToFrame->Transform (&xx,&yy);
+        m_RegionCenter = mgFactory.CreateCoordinateXY (xx,yy);
+
+        // Generate the polygon; then convert to frame coordinates.
+        regionBoundaryInGridCrs = csFactory.GridBoundary (southwest,northeast);
+        regionBoundaryInGridCrs->SetMaxCurvePoints (maxPoints);
+        m_RegionBoundary = regionBoundaryInGridCrs->GetBoundary (gridToFrame,curvePrecision);
+
+        // Generate and clip each of the four bounding lines.
+        lineString = gridToFrame->GridLine (southwest,southeast,curvePrecision,maxPoints);
+        m_SouthLine = frameBoundary->ClipLineString (lineString);
+        
+        lineString = gridToFrame->GridLine (southeast,northeast,curvePrecision,maxPoints);
+        m_EastLine = frameBoundary->ClipLineString (lineString);
+
+        lineString = gridToFrame->GridLine (northeast,northwest,curvePrecision,maxPoints);
+        m_NorthLine = frameBoundary->ClipLineString (lineString);
+
+        lineString = gridToFrame->GridLine (northwest,southwest,curvePrecision,maxPoints);
+        m_WestLine = frameBoundary->ClipLineString (lineString);
+    MG_CATCH_AND_THROW(L"MgCoordinateSystemGridBoundary.SetBoundaryExtents")
+}
 STRING CCoordinateSystemGridRegion::GetLabel ()
 {
     return m_RegionLabel;
 }
-MgPolygon* CCoordinateSystemGridRegion::GetPolygon ()
+MgCoordinate* CCoordinateSystemGridRegion::GetRegionCenter (void)
 {
-    return SAFE_ADDREF(m_Polygon.p);
+    return SAFE_ADDREF(m_RegionCenter.p);
 }
+MgPolygon* CCoordinateSystemGridRegion::GetRegionBoundary ()
+{
+    return SAFE_ADDREF(m_RegionBoundary.p);
+}
+MgLineStringCollection* CCoordinateSystemGridRegion::GetSouthLine (void)
+{
+    return SAFE_ADDREF(m_SouthLine.p);
+}
+MgLineStringCollection* CCoordinateSystemGridRegion::GetEastLine (void)
+{
+    return SAFE_ADDREF(m_EastLine.p);
+}
+MgLineStringCollection* CCoordinateSystemGridRegion::GetNorthLine (void)
+{
+    return SAFE_ADDREF(m_NorthLine.p);
+}
+MgLineStringCollection* CCoordinateSystemGridRegion::GetWestLine (void)
+{
+    return SAFE_ADDREF(m_WestLine.p);
+}
+
+void CCoordinateSystemGridRegion::SetRegionBoundary (MgPolygon* boundary)
+{
+    m_RegionBoundary = SAFE_ADDREF (boundary);
+}
+void CCoordinateSystemGridRegion::SetSouthLine (MgLineStringCollection* southLine)
+{
+    m_SouthLine = SAFE_ADDREF(southLine);
+}
+void CCoordinateSystemGridRegion::SetEastLine (MgLineStringCollection* eastLine)
+{
+    m_EastLine = SAFE_ADDREF(eastLine);
+}
+void CCoordinateSystemGridRegion::SetNorthLine (MgLineStringCollection* northLine)
+{
+    m_NorthLine = SAFE_ADDREF(northLine);
+}
+void CCoordinateSystemGridRegion::SetWestLine (MgLineStringCollection* westLine)
+{
+    m_WestLine = SAFE_ADDREF(westLine);
+}
 void CCoordinateSystemGridRegion::Dispose ()
 {
     delete this;
@@ -758,6 +861,7 @@
 CCoordinateSystemGridTick::CCoordinateSystemGridTick (INT32 orientation,double value)
                                                         :
                                                       MgCoordinateSystemGridTick (),
+                                                      m_OnGridLine               (false),
                                                       m_Orientation              (orientation),
                                                       m_Value                    (value),
                                                       m_Position                 (),
@@ -767,6 +871,10 @@
 CCoordinateSystemGridTick::~CCoordinateSystemGridTick ()
 {
 }
+void CCoordinateSystemGridTick::SetOnGridLine (bool isOnGridLine)
+{
+    m_OnGridLine = isOnGridLine;
+}
 void CCoordinateSystemGridTick::SetOrientation (INT32 orientation)
 {
     m_Orientation = orientation;
@@ -783,6 +891,11 @@
 {
     m_Direction = SAFE_ADDREF(direction);
 }
+
+bool CCoordinateSystemGridTick::GetIsOnGridLine (void)
+{
+    return m_OnGridLine;
+}
 INT32 CCoordinateSystemGridTick::GetTickOrientation ()
 {
     return m_Orientation;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -165,8 +165,23 @@
     /// the new coordinate system.
     MgPolygon* GetBoundary (void) const;
 
-    ////////////////////////////////////////////////////////////////////////////
+     ////////////////////////////////////////////////////////////////////////////
     /// \brief
+    /// Sets a limit on thenumber of points generated by the complex curve
+    /// approximation algorithm.
+    /// \param maxPoints
+    /// The complex curve approximation algorithm cleanly terminates after this
+    /// number of points has been generated.
+    /// /remarks
+    /// The actual number of points in a complex curve approximation may contain
+    /// as many as twice this number of points.  It is when this number of
+    /// points is exceeded that the algorithms starts a clean termination.<p>
+    /// This value is used in the "GetBoundary" function to reduce the
+    /// probability of a runaway calculation.
+    void SetMaxCurvePoints (INT32 maxPoints);
+
+   ////////////////////////////////////////////////////////////////////////////
+    /// \brief
     /// Returns the extents of the grid boundary.
     /// \param eastMin
     /// The minimum easting (i.e. X) ordinate value is returned here.
@@ -180,8 +195,8 @@
     /// Especially useful after the internal boundary is converted to a
     /// different coordinate system.
     void GetBoundaryExtents (double& eastMin,double& eastMax,double& northMin,double& northMax) const;
-    
-    ////////////////////////////////////////////////////////////////////////////
+
+     ////////////////////////////////////////////////////////////////////////////
     /// \brief
     /// Returns the internal grid boundary, in the form of an MgPolygon object,
     /// after the boundary hbas been converted using the provided coordinate
@@ -219,12 +234,13 @@
     /// concave polygons, but this has not bee tested.  Interior rings in the
     /// internal polygon object are ignored at this time.
     MgLineStringCollection* ClipLineString (MgLineString* lineString) const;
+
 protected:
-
     ////////////////////////////////////////////////////////////////////////////
     /// \brief
-    /// Satifies the pur virtual function of the MgDispose base class from which
-    /// this object is derived.  Essentially causes the destructor to be called.
+    /// Satifies the pure virtual function of the MgDispose base class from
+    /// which this object is derived.  Essentially causes the destructor to be
+    /// called.
     void Dispose (void);
 private:
     // The transform used in the following function is more sophisicated than the
@@ -248,17 +264,17 @@
     CCoordinateSystemGridLine (const CCoordinateSystemGridLine& source);
     ~CCoordinateSystemGridLine (void);
     
-    virtual INT32 GetGridOrientation(void);
-    virtual double GetRealValue(void);
-    virtual INT32 GetCount (void);
-    virtual MgLineString* GetSegment (INT32 index);
-    virtual MgLineStringCollection* GetSegmentCollection (void);
+    INT32 GetGridOrientation(void);
+    double GetRealValue(void);
+    INT32 GetCount (void);
+    MgLineString* GetSegment (INT32 index);
+    MgLineStringCollection* GetSegmentCollection (void);
 
-    virtual void SetGridOrientation (INT32 orientation);
-    virtual void SetRealValue (double realValue);
-    virtual void ClearSegments (void);
-    virtual void AddSegment (MgLineString* newSegment);
-    virtual void SetSegmentCollection (MgLineStringCollection* segmentCollection);
+    void SetGridOrientation (INT32 orientation);
+    void SetRealValue (double realValue);
+    void ClearSegments (void);
+    void AddSegment (MgLineString* newSegment);
+    void SetSegmentCollection (MgLineStringCollection* segmentCollection);
 protected:
     void Dispose (void);
 
@@ -268,20 +284,45 @@
 };
 
 //=============================================================================
-// CCoordinateSystemGridregion  --  Implements MgCoordinateSystemGridregion
+// CCoordinateSystemGridregion  --  Implements MgCoordinateSystemGridRegion
 //
 class CCoordinateSystemGridRegion : public MgCoordinateSystemGridRegion
 {
 public:
-    CCoordinateSystemGridRegion (STRING label,MgPolygon* polygon);
-    
-    virtual STRING GetLabel ();
-    virtual MgPolygon* GetPolygon ();
+    CCoordinateSystemGridRegion (STRING label,MgCoordinateSystemGridBoundary* frameBoundary,
+                                              MgCoordinateSystemTransform* gridToFrame,
+                                              MgCoordinate* southwest,
+                                              MgCoordinate* northeast,
+                                              double curvePrecision,
+                                              INT32 maxPoints);
 
+    STRING GetLabel ();
+    MgCoordinate* GetRegionCenter (void);
+    MgPolygon* GetRegionBoundary (void);
+
+    // Returns from the following are clipped, thus they are collections of
+    // line strings due to the rare but possible case the indicated line
+    // enters and leaves the frame boundary more than once.
+    MgLineStringCollection* GetSouthLine (void);
+    MgLineStringCollection* GetEastLine (void);
+    MgLineStringCollection* GetNorthLine (void);
+    MgLineStringCollection* GetWestLine (void);
+
+    void SetRegionBoundary (MgPolygon* boundary);
+    void SetSouthLine (MgLineStringCollection* southLine);
+    void SetEastLine (MgLineStringCollection* eastLine);
+    void SetNorthLine (MgLineStringCollection* northLine);
+    void SetWestLine (MgLineStringCollection* westLine);
+
 protected:
     void Dispose (void);
     STRING m_RegionLabel;
-    Ptr<MgPolygon> m_Polygon;
+    Ptr<MgCoordinate> m_RegionCenter;
+    Ptr<MgPolygon> m_RegionBoundary;
+    Ptr<MgLineStringCollection> m_SouthLine;
+    Ptr<MgLineStringCollection> m_EastLine;
+    Ptr<MgLineStringCollection> m_NorthLine;
+    Ptr<MgLineStringCollection> m_WestLine;
 
 private:
     CCoordinateSystemGridRegion (void);
@@ -300,19 +341,22 @@
     ~CCoordinateSystemGridTick (void);
     CCoordinateSystemGridTick& operator= (const CCoordinateSystemGridTick& rhs);
 
-    virtual void SetOrientation (INT32 orientation);
-    virtual void SetValue (double value);
-    virtual void SetPosition (MgCoordinate* position);
-    virtual void SetDirection (MgCoordinate* direction);
+    void SetOnGridLine (bool isOnGridLine);
+    void SetOrientation (INT32 orientation);
+    void SetValue (double value);
+    void SetPosition (MgCoordinate* position);
+    void SetDirection (MgCoordinate* direction);
 
-    virtual INT32 GetTickOrientation (void);
-    virtual double GetValue (void);
-    virtual MgCoordinate* GetPosition (void);
-    virtual MgCoordinate* GetDirectionVector (void);
+    bool GetIsOnGridLine (void);
+    INT32 GetTickOrientation (void);
+    double GetValue (void);
+    MgCoordinate* GetPosition (void);
+    MgCoordinate* GetDirectionVector (void);
 
 protected:
     void Dispose (void);
 
+    bool m_OnGridLine;
     INT32 m_Orientation;
     double m_Value;
     Ptr<MgCoordinate> m_Position;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-09-10 19:04:39 UTC (rev 4217)
@@ -414,7 +414,7 @@
         {
             mgrsZoneGrid = m_ZoneCollection->GetItem (index);
             Ptr<MgCoordinateSystemGridRegionCollection> aGridRegionCollection;
-            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (specification);
+            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (m_GridBoundary,specification);
             theGridRegionCollection->AddCollection (aGridRegionCollection);
         }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrs::GetGridRegions")
@@ -930,7 +930,7 @@
     }
     else
     {
-        index = (static_cast<INT32>(latitude) % 8) + 12;
+        index = (static_cast<INT32>(latitude) / 8) + 12;
         if (index == 22) index = 21;
     }
     return index;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -23,18 +23,11 @@
 
 class CCoordinateSystemMgrs : public MgCoordinateSystemMgrs
 {
-    //struct CCoordinateSystemUtmCodeMap
-    //{
-    //    INT32 ZoneNbr;
-    //    wchar_t ZoneCode [14];
-    //};
-    //static const CCordinateSystemUtmCodeMap UtmCodeMap [];
- 
-struct CCoordinateSystemMgrsSeries
-{
-	wchar_t easting [9];
-	wchar_t northing [21];
-};
+    struct CCoordinateSystemMgrsSeries
+    {
+	    wchar_t easting [9];
+	    wchar_t northing [21];
+    };
 
 public:
     // Static Constants, Variables (hopefully not), and Functions.
@@ -119,7 +112,7 @@
     INT32 m_nLastError;
     Ptr<MgCoordinateSystem> m_pCsTarget;
     struct cs_Mgrs_* m_pCsMgrs;
-    Ptr<MgCoordinateSystemGridBoundary> m_GridBoundary;
+    Ptr<MgCoordinateSystemGridBoundary> m_GridBoundary; // actually the frame boundary
     Ptr<CCoordinateSystemMgrsZoneCollection> m_ZoneCollection;
 
     // The following CCoordinateSystemOneGrid objects are used to generate

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-09-10 19:04:39 UTC (rev 4217)
@@ -51,9 +51,10 @@
 CCoordinateSystemMgrsZone::~CCoordinateSystemMgrsZone (void)
 {
 }
-CCoordinateSystemGridRegionCollection* CCoordinateSystemMgrsZone::GetGridRegions (MgCoordinateSystemGridSpecification* specification)
+CCoordinateSystemGridRegionCollection* CCoordinateSystemMgrsZone::GetGridRegions (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                                                  MgCoordinateSystemGridSpecification* specification)
 {
-    BuildRegionCollection (specification);
+    BuildRegionCollection (frameBoundary,specification);
     return SAFE_ADDREF(m_RegionCollection.p);
 }
 INT32 CCoordinateSystemMgrsZone::GetUtmZoneNbr (void)
@@ -63,16 +64,19 @@
     // is the uninitialized/unknown/error value.
     return m_UtmZone;
 }
-void CCoordinateSystemMgrsZone::BuildRegionCollection (MgCoordinateSystemGridSpecification* specification)
+void CCoordinateSystemMgrsZone::BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                       MgCoordinateSystemGridSpecification* specification)
 {
     double curvePrecision;
 
     curvePrecision = specification->GetCurvePrecision ();
-    BuildMajorRegions (curvePrecision);
-    BuildMinorRegions (curvePrecision);
+    BuildMajorRegions (frameBoundary,curvePrecision);
+    BuildMinorRegions (frameBoundary,curvePrecision);
 }
-void CCoordinateSystemMgrsZone::BuildMajorRegions (double curvePrecision)
+void CCoordinateSystemMgrsZone::BuildMajorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double curvePrecision)
 {
+    const INT32 maxPoints = 512;
+
     wchar_t gridZoneLetter;
     INT32 utmZoneNbr;
     INT32 gridZoneIndex;
@@ -84,17 +88,16 @@
     STRING designation;
     wchar_t wcBufr [128];
  
-    MgCoordinateSystemFactory csFactory;
-    
     Ptr<MgCoordinate> southwest;
     Ptr<MgCoordinate> northeast;
-    Ptr<MgPolygon> pPolygon;
     Ptr<MgCoordinateSystem> llCRS;
     Ptr<MgCoordinateSystem> frameCRS;
     Ptr<MgCoordinateSystemTransform> toFrameTransform;
     Ptr<CCoordinateSystemGridBoundary> rgnBoundary;
     Ptr<CCoordinateSystemGridRegion> pMjrRegion;
 
+    MgCoordinateSystemFactory csFactory;
+
     MG_TRY ()
         southwest = new MgCoordinateXY ();
         northeast = new MgCoordinateXY ();
@@ -130,14 +133,15 @@
 
             for (latIdx = firstLat;latIdx < lastLat;latIdx += 8)
             {
+                // TODO: Need to adjust the region boundaries to account for
+                // the screwy stuff which happens in southern Norway and the
+                // Svaldberg Islands.
                 latMin = static_cast<double>(latIdx);
                 latMax = latMin + 8.0;
                 southwest->SetX (lngMin);
                 southwest->SetY (latMin);
                 northeast->SetX (lngMax);
                 northeast->SetY (latMax);
-                rgnBoundary = new CCoordinateSystemGridBoundary (southwest,northeast);
-                pPolygon = rgnBoundary->GetBoundary (toFrameTransform,curvePrecision);
 
                 // We have the polygon, we need the designation.
                 gridZoneIndex = CCoordinateSystemMgrs::GridZoneDesignationIndex (latMin + 1.0,centralMeridian);
@@ -146,14 +150,29 @@
                 STRING designation (wcBufr);
 
                 // Construct the region object and add it to the region collection.
-                pMjrRegion = new CCoordinateSystemGridRegion (designation,pPolygon);
+                pMjrRegion = new CCoordinateSystemGridRegion (designation,frameBoundary,
+                                                                          toFrameTransform,
+                                                                          southwest,
+                                                                          northeast,
+                                                                          curvePrecision,
+                                                                          maxPoints);
                 m_RegionCollection->Add (pMjrRegion);
             }
         }
+        else if (m_UtmZone == 61)
+        {
+            //TODO: need to generate regions for the north polar region.
+        }
+        else if (m_UtmZone == -61)
+        {
+            //TODO: need to generate regions for the south polar region.
+        }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemOneGrid::BuildMajorRegions")
 }
-void CCoordinateSystemMgrsZone::BuildMinorRegions (double curvePrecision)
+void CCoordinateSystemMgrsZone::BuildMinorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double curvePrecision)
 {
+    const INT32 maxPoints = 512;
+
     INT32 beginEast, endEast;
     INT32 beginNorth, endNorth;
     INT32 eastIndex, northIndex;
@@ -164,11 +183,11 @@
 
     Ptr<MgCoordinate> southwest;
     Ptr<MgCoordinate> northeast;
-    Ptr<MgPolygon> pPolygon;
+    Ptr<MgCoordinateSystemTransform> gridToFrameXfrom;
     Ptr<CCoordinateSystemGridBoundary> rgnBoundary;
     Ptr<CCoordinateSystemGridRegion> pMnrRegion;
     MgCoordinateSystemFactory csFactory;
-    
+
     MG_TRY ()
         southwest = new MgCoordinateXY ();
         northeast = new MgCoordinateXY ();
@@ -177,6 +196,11 @@
         // the grid boundary has not been generated for this object yet.
         GetGridExtents (eastMin,eastMax,northMin,northMax,curvePrecision);
 
+        // Generation of regions requires conversion of region boundaries to
+        // frame coordinates.  The OneGrid base class has this transformation
+        // available.
+        gridToFrameXfrom = GetGridToFrameXform ();
+
         // Expand the min/max values to the 100K boundaries of the minor regions.
         // A little overkill here as the extent values should never be negative.
         delta = fabs (fmod (eastMin,100000.0));
@@ -201,12 +225,7 @@
                 northeast->SetX (static_cast<double>(eastIndex + 100000));
                 northeast->SetY (static_cast<double>(northIndex + 100000));
                 
-                // Convert it to a boundary which we can transform, and then to
-                // a MgPolygon which is what we really need..
-                rgnBoundary = new CCoordinateSystemGridBoundary (southwest,northeast);
-                pPolygon = rgnBoundary->GetBoundary (m_ToFrameXform,curvePrecision);
-
-                // Now we need the designation.  The comes from the MgCoordinateSystemMgrs object that knows about the lettering scheme.
+                 // Now we need the designation.  The comes from the MgCoordinateSystemMgrs object that knows about the lettering scheme.
                 // Unfortunately, we don't have a reference to the host Mgrs object, so we're going to have to know
                 /// about the lettering scheme.
                 STRING designation = CCoordinateSystemMgrs::GridSquareDesignation (m_UtmZone,static_cast<double>(eastIndex + 1),
@@ -214,7 +233,12 @@
                                                                                              m_LetteringScheme);
 
                 // Construct the region object and add it to the region collection.
-                pMnrRegion = new CCoordinateSystemGridRegion (designation,pPolygon);
+                pMnrRegion = new CCoordinateSystemGridRegion (designation,frameBoundary,
+                                                                          gridToFrameXfrom,
+                                                                          southwest,
+                                                                          northeast,
+                                                                          curvePrecision,
+                                                                          maxPoints);
                 m_RegionCollection->Add (pMnrRegion);
             }
         }

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -53,14 +53,16 @@
                                INT8 letteringScheme);
     ~CCoordinateSystemMgrsZone (void);
 
-    CCoordinateSystemGridRegionCollection* GetGridRegions (MgCoordinateSystemGridSpecification* specification);
+    CCoordinateSystemGridRegionCollection* GetGridRegions (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                           MgCoordinateSystemGridSpecification* specification);
     INT32 GetUtmZoneNbr (void);
  
 protected:
-    void BuildRegionCollection (MgCoordinateSystemGridSpecification* specification);
+    void BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
+                                MgCoordinateSystemGridSpecification* specification);
 private:
-    void BuildMajorRegions (double boundaryPrecision);
-    void BuildMinorRegions (double boundaryPrecision);
+    void BuildMajorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double boundaryPrecision);
+    void BuildMinorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double boundaryPrecision);
     ///////////////////////////////////////////////////////////////////////////
     // Data members
     // m_UtmZoneNbr is positive for northern hemisphere, negative for the

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-09-10 19:04:39 UTC (rev 4217)
@@ -244,9 +244,12 @@
 }
 CCoordinateSystemGridTickCollection* CCoordinateSystemOneGrid::GetBoundaryTicks (MgCoordinateSystemGridSpecification* specs)
 {
+    bool isOnGridLine;
+
     INT32 status;
     INT32 orientation;
 
+    double tmpDbl;
     double delta;
     double increment;
     double segLength;
@@ -340,6 +343,10 @@
                     Ptr<MgCoordinate> unitVector = mgFactory.CreateCoordinateXY (deltaX / segLength,deltaY / segLength);
                     Ptr<CCoordinateSystemGridTick> tickPtr;
                     tickPtr = new CCoordinateSystemGridTick (orientation,ordinateValue);
+                    tmpDbl = (ordinateValue - specs->GetEastingBase ());
+                    tmpDbl = fmod (tmpDbl,specs->GetEastingIncrement ());
+                    isOnGridLine = fabs (tmpDbl) < 1.0E-08;
+                    tickPtr->SetOnGridLine (isOnGridLine);
                     tickPtr->SetDirection (unitVector);
                     tickPtr->SetPosition (tickPoint);
                     tickCollection->Add (tickPtr);
@@ -368,6 +375,9 @@
                     Ptr<MgCoordinate> unitVector = mgFactory.CreateCoordinateXY (deltaX / segLength,deltaY / segLength);
                     Ptr<CCoordinateSystemGridTick> tickPtr;
                     tickPtr = new CCoordinateSystemGridTick (orientation,ordinateValue);
+                    tmpDbl = (ordinateValue - specs->GetNorthingBase ());
+                    tmpDbl = fmod (tmpDbl,specs->GetNorthingIncrement ());
+                    isOnGridLine = fabs (tmpDbl) < 1.0E-08;
                     tickPtr->SetDirection (unitVector);
                     tickPtr->SetPosition (tickPoint);
                     tickCollection->Add (tickPtr);
@@ -377,6 +387,10 @@
     MG_CATCH_AND_THROW(L"MgCoordinateSystemOneGrid::GetGridLines")
     return tickCollection.Detach ();
 }
+MgCoordinateSystemGridBoundary* CCoordinateSystemOneGrid::GetFrameBoundary (void)
+{
+    return SAFE_ADDREF (m_FrameBoundary.p);
+}
 MgCoordinateSystem* CCoordinateSystemOneGrid::GetFrameCRS ()
 {
     return SAFE_ADDREF (m_FrameCRS.p);
@@ -385,6 +399,14 @@
 {
     return SAFE_ADDREF (m_GridCRS.p);
 }
+MgCoordinateSystemTransform* CCoordinateSystemOneGrid::GetGridToFrameXform (void)
+{
+    return SAFE_ADDREF (m_ToFrameXform.p);
+}
+MgCoordinateSystemTransform* CCoordinateSystemOneGrid::GetFrameToGridXform (void)
+{
+    return SAFE_ADDREF (m_ToGridXform.p);
+}
 void CCoordinateSystemOneGrid::GenerateGridBoundary (double boundaryPrecision)
 {
     bool generateGridBoundary;
@@ -415,7 +437,7 @@
 
     MG_TRY ()
         llCRS = csFactory.CreateFromCode (L"LL");
-        llTransform = csFactory.GetTransform(m_GridCRS,llCRS);
+        llTransform = csFactory.GetTransform(m_FrameCRS,llCRS);
         pPolygon = m_FrameBoundary->GetBoundary (llTransform,precision);
         llBoundary = csFactory.GridBoundary (pPolygon);
         llBoundary->GetBoundaryExtents (longMin,longMax,latMin,latMax);
@@ -444,7 +466,7 @@
 //=============================================================================
 // This object was invented to carry multiple MGRS grids, but is no longer used
 // as there is now a CCoordinateSystemMgrsZone object and a related collection
-// object.  WHen we're ready for code complete and we don't seem to need this
+// object.  When we're ready for code complete and we don't seem to need this
 // for anything, we should delete it. 
 CCoordinateSystemGridCollection::CCoordinateSystemGridCollection (void)
                                         :

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -66,8 +66,11 @@
     CCoordinateSystemGridTickCollection* GetBoundaryTicks (MgCoordinateSystemGridSpecification* specs);
 
 protected:
+    MgCoordinateSystemGridBoundary* GetFrameBoundary (void);
     MgCoordinateSystem* GetFrameCRS (void);
     MgCoordinateSystem* GetGridCRS (void);
+    MgCoordinateSystemTransform* GetGridToFrameXform (void);
+    MgCoordinateSystemTransform* GetFrameToGridXform (void);
     void GenerateGridBoundary (double boundaryPrecision);
     void GetGeographicExtents (double& longMin,double& longMax,double& latMin,double& latMax,double precision = 1.0E-05);
     void GetGridExtents (double& eastMin,double& eastMax,double& northMin,double& northMax,double precision = 0.25);

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemFactory.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemFactory.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemFactory.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -153,34 +153,26 @@
     // Grids and Graticules -- General
 
     ///////////////////////////////////////////////////////////////////////////
-    /// <summary>
-    /// Constructs a grid boundary object.  Externally, grid objects are in
-    /// viewport coordinates and define the extents of the region within
-    /// which a grid is to be drawn.  Such objects are often simple
-    /// rectangles, but his is not a requirement.
-    /// </summary>
-    /// <param name="southwest">
+    /// /brief
+    /// Constructs a grid boundary object.
+    /// /param southwest
     /// The coordinates of the the southwest corner of a rectangular region
     /// which represents the grid region.  This point <b>MUST</b> indeed be
-    /// sothwest of the coordinate provided by the <c>northeast</c> parameter.
-    /// </param>
-    /// <param name="northeast">
+    /// southwest of the coordinate provided by the <c>northeast</c> parameter.
+    /// /param northeast
     /// The coordinates of the the northeast corner of a rectangular region
     /// which represents the grid region.  This point <b>MUST</b> indeed be
     /// northeast of the coordinate provided by the <c>southwest</c> parameter.
-    /// </param>
-    /// <returns>
+    /// /return
     /// Returns the grid boundary in the ofrm used by the grid/graticule
     /// sub-system.
-    /// </returns>
-    /// <exception cref="MgOutOfMemoryException">
+    /// \exception MgOutOfMemoryException
     /// Thrown in the event of heap memory allocation failure.
-    /// </exception>
-    /// <remarks>
-    /// Internally, the grid boundary is maintained as an MgPolygon object
-    /// with no interior rings.  Otfen this is in the form of a rectangle,
-    /// but his should not be relied on.
-    /// </remarks>
+    /// /remarks
+    /// Externally, grid bundary objects are in viewport coordinates and
+    /// define the extents of the region within which a grid is to be drawn.
+    /// Such objects are often simple rectangles, but his is not a
+    /// requirement.
     virtual MgCoordinateSystemGridBoundary* GridBoundary(MgCoordinate* southwest,
                                                          MgCoordinate* northeast);
 
@@ -201,6 +193,8 @@
     /// Thrown in the event of heap memory allocation failure.
     /// </exception>
     /// <remarks>
+    /// The <c>boundary</c> argument need not be a rectangle, but is assumed
+    /// to be closed.
     /// </remarks>
     virtual MgCoordinateSystemGridBoundary* GridBoundary(MgPolygon* boundary);
 
@@ -211,11 +205,16 @@
     /// </summary>
     /// <returns>
     /// An object which carries all of the several parameter which determine
-    /// nature of a grid or graticule and any sub-feature tereof.
+    /// nature of a grid or graticule and any sub-feature thereof.
     /// </returns>
     /// <exception cref="std::bad_alloc">
     /// Thrown in the event of a heap memory allocation failure.
     /// </exception>
+    /// <remarks>
+    /// When manufactured by this overload, the consuming application must
+    /// set all values to valid values before using the returned object
+    /// in any way.
+    /// </remarks>
     virtual MgCoordinateSystemGridSpecification* GridSpecification (void);
 
     ///////////////////////////////////////////////////////////////////////////

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -63,12 +63,23 @@
 class MgCoordinateSystemGridSpecializationType
 {
 PUBLISHED_API:
-    static const INT32 None              = 0;           // not specified as yet; initialize to this value
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Not specified yet, initialize to this value.
+    static const INT32 None              = 0;
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Generic grid of a specified coordinate system; may be
+    /// geographic or projected.
     static const INT32 Generic           = (0 + 1);     // Generic grid of a specified coordinate system;
                                                         // may be geographic or projected
-    static const INT32 MGRS              = (16 + 1);    // Military Grid Reference System
-    static const INT32 USNG              = (16 + 2);    // United States National Grid
-    static const INT32 Unknown           = (65366);     // indicates a failure of an algorithm
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Specialized grid: MGRS (Military Grid Reference System)
+    static const INT32 MGRS              = (16 + 1);
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Specialized grid: USNG (United States National Grid)
+    static const INT32 USNG              = (16 + 2);
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Indicates the failure of an algorithm or other problem.
+    static const INT32 Unknown           = (65366);
 };
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -87,9 +98,17 @@
 class MgCoordinateSystemGridOrientation
 {
 PUBLISHED_API:
-    static const INT8 None = 0;             // not specified as yet; initialize to this value
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Not specified yet, initialize to this value.
+    static const INT8 None = 0;
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief The object represents a constant easting value.
     static const INT8 EastWest = 1;         // generally indicates a vertical grid line
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief The object represents a constant northing value.
     static const INT8 NorthSouth = 2;       // generally indicates a horizontal grid line
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief Indicates the failure of an algorithm or other problem.
     static const INT8 Unknown = 3;          // indicates a failure of an algorithm
 };
 
@@ -617,7 +636,7 @@
 /// This object is used to maintain the definition of the boundary of a
 /// specific grid or graticule.  Externally, a
 /// <c>MgCoordinateSystemGridBoundary</c> object will be in viewport
-/// coordinates.  Internally, objects of this type are oftyen used to the
+/// coordinates.  Internally, objects of this type are often used to the
 /// carry grid boundaries in grid coordinates, and also greographic
 /// coordinates.<p>
 /// Grid boundaries iusually start out as rectangles, but are often converted
@@ -635,6 +654,7 @@
     virtual MgPolygon* GetBoundary (void) const=0;
 INTERNAL_API:
 
+    virtual void SetMaxCurvePoints (INT32 maxPoints) = 0;
     virtual void GetBoundaryExtents (double& eastMin,double& eastMax,double& northMin,double& northMax) const = 0;
     virtual MgPolygon* GetBoundary (MgCoordinateSystemTransform* transformation,double precision) = 0;
     virtual MgLineStringCollection* ClipLineString (MgLineString* lineString) const=0;
@@ -712,7 +732,18 @@
 {
 PUBLISHED_API:
     virtual STRING GetLabel () = 0;
-    virtual MgPolygon* GetPolygon() = 0;
+    virtual MgCoordinate* GetRegionCenter (void) = 0;
+    virtual MgPolygon* GetRegionBoundary (void) = 0;
+
+    // The returns from the following members are clipped to the frame boundary
+    // of the grid object from which the region object was obtained.  Since it
+    // is possible (rare, but possible) that a region boundary line enters and
+    // leaves the frame boundary more than once.
+    virtual MgLineStringCollection* GetSouthLine (void) = 0;
+    virtual MgLineStringCollection* GetEastLine (void) = 0;
+    virtual MgLineStringCollection* GetNorthLine (void) = 0;
+    virtual MgLineStringCollection* GetWestLine (void) = 0;
+
 INTERNAL_API:
 protected:
     INT32 GetClassId(){return m_cls_id;};
@@ -731,6 +762,7 @@
 class MG_GEOMETRY_API MgCoordinateSystemGridTick : public MgGuardDisposable
 {
 PUBLISHED_API:
+    virtual bool GetIsOnGridLine () = 0;
     virtual INT32 GetTickOrientation () = 0;
     virtual double GetValue () = 0;
     virtual MgCoordinate* GetPosition () = 0;

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h	2009-09-10 18:58:19 UTC (rev 4216)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h	2009-09-10 19:04:39 UTC (rev 4217)
@@ -18,14 +18,74 @@
 #ifndef _MGCOORDINATESYSTEMMGRS_H_
 #define _MGCOORDINATESYSTEMMGRS_H_
 
+///////////////////////////////////////////////////////////////////////////////
+/// This object carries most, if not all, intelligence specific to the MGRS
+/// (Military Grid Reference System) grid standard.  It can be used at two
+/// distinct levels, depending upon how it is manufactured.
+///
+/// When manufactured with an ellipsoid/datum specification, this object is
+/// suitable only for conversion of geographic coordinates to MGRS strings and
+/// vice-versa.
+///
+/// WHen manufactured with a frame coordinate system with a grid boundary
+/// subsequently supplied, the resulting object is capable of NGRS string
+/// conversions AND the generation of MGRS grids.
+///
+/// When manufactured using a frame coordinate system and subsequent
+/// provision of a frame boundary (see base class MgCoordinateSystemGridBase)
+/// the members derived from the MgCoordinateSystemGridBase base class
+/// can be used for MGRS grid drawing purposes.
 class MgCoordinateSystemMgrs : public MgCoordinateSystemGridBase
 {
 PUBLISHED_API:
-    //section that reads/writes MGRS coordinates
+    // section that reads/writes MGRS coordinates
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief
+    /// Converts a geographic coordinate to MGRS string form.
+    /// /param dLongitude
+    /// Longitude of the geographic position to be converted, in degrees
+    /// relative to Greenwich.  Use negative value for west longitude.
+    /// /param dLatitude
+    /// Latitude of the geographic position to be converted, in degrees.
+    /// Use negative value for south latitude.
+    /// /param nPrecision
+    /// A value between zero and five, indicates the precision of the
+    /// numeric portion of the returned MGRS designation.
+    /// /returns
+    /// The MGRs representation for the given point.
     virtual STRING ConvertFromLonLat(double dLongitude, double dLatitude, INT32 nPrecision)=0;
+    
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief
+    /// Converts a geographic coordinate to MGRS string form.
+    /// /param pLonLat
+    /// The geographic position to be converted.  X coordinate is the longitude
+    /// in degrees relative to Greenwich, negative indicating west longitude.
+    /// Y coordinate is latitude in degrees, negative indicating south latitude.
+    /// /param nPrecision
+    /// A value between zero and five, indicates the precision of the
+    /// numeric portion of the returned MGRS designation.
+    /// /returns
+    /// The MGRs representation for the given point.
     virtual STRING ConvertFromLonLat(MgCoordinate* pLonLat, INT32 nPrecision)=0;
+
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief
+    /// Converts an MGRS string to geographic coordinates.
+    /// /param sMgrs
+    /// The MGRS string to be converted.
+    /// /returns
+    /// The geographic coordinates of the location identified by the provided
+    /// MGRS string.
     virtual MgCoordinate* ConvertToLonLat(CREFSTRING sMgrs)=0;
 
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief
+    /// Returns a value as defined by the MgCoordinateSystemMgrsLetteringScheme
+    /// object indicating which lettering scheme is currently active.
+    /// /returns
+    /// Either MgCoordinateSystemMgrsLetteringScheme::Normal or
+    /// MgCoordinateSystemMgrsLetteringScheme::Alternative
     virtual INT8 GetLetteringScheme()=0;
 
 INTERNAL_API:



More information about the mapguide-commits mailing list