Exemple #1
0
void CCoordinateSystemGridBoundary::SetBoundaryExtents (MgCoordinate* southwest,
                                                        MgCoordinate* northeast)
{
    MgGeometryFactory factory;
    Ptr<MgCoordinate> swPnt;
    Ptr<MgCoordinate> sePnt;
    Ptr<MgCoordinate> nePnt;
    Ptr<MgCoordinate> nwPnt;
    Ptr<MgCoordinate> clPnt;
    Ptr<MgCoordinateCollection> collection;

    MG_TRY()
        swPnt = factory.CreateCoordinateXY(southwest->GetX(),southwest->GetY());
        sePnt = factory.CreateCoordinateXY(northeast->GetX(),southwest->GetY());
        nePnt = factory.CreateCoordinateXY(northeast->GetX(),northeast->GetY());
        nwPnt = factory.CreateCoordinateXY(southwest->GetX(),northeast->GetY());
        clPnt = factory.CreateCoordinateXY(southwest->GetX(),southwest->GetY());

        if (!swPnt|| !swPnt || !nePnt || !nwPnt ||!clPnt)
        {
            throw new MgOutOfMemoryException(L"MgCoordinateSystemGridBoundary.SetBoundaryExtents",
                                             __LINE__, __WFILE__, NULL, L"", NULL);
        }

        collection = new MgCoordinateCollection();
        if (collection == NULL)
        {
            throw new MgOutOfMemoryException(L"MgCoordinateSystemGridBoundary.SetBoundaryExtents",
                                             __LINE__, __WFILE__, NULL, L"", NULL);
        }
        collection->Add (swPnt);
        collection->Add (sePnt);
        collection->Add (nePnt);
        collection->Add (nwPnt);
        collection->Add (clPnt);

        Ptr<MgLinearRing> ring = factory.CreateLinearRing (collection);
        if (ring == 0)
        {
            throw new MgOutOfMemoryException(L"MgCoordinateSystemGridBoundary.SetBoundaryExtents",
                                             __LINE__, __WFILE__, NULL, L"", NULL);
        }
        m_GridBoundary = factory.CreatePolygon (ring,NULL);
    MG_CATCH_AND_THROW(L"MgCoordinateSystemGridBoundary.SetBoundaryExtents")
}
Exemple #2
0
// This API has been found to be problematical in the initial release.  It
// will be deprecated in the next release.
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                   ()
{
    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")
}
Exemple #3
0
void CCoordinateSystemMgrsZone::BuildMinorRegions (CCoordinateSystemGridRegionCollection* regionCollection,
                                                   MgCoordinateSystemGridBoundary* frameBoundary,
                                                   double curvePrecision)
{
    static const INT32 iK100Km = 100000;
    static const double rK100Km = 100000.0;
    const INT32 maxPoints = 254;

    bool swPntIsIn;
    bool sePntIsIn;
    bool nePntIsIn;
    bool nwPntIsIn;

    INT32 beginEast, endEast;
    INT32 beginNorth, endNorth;
    INT32 eastIndex, northIndex;

    double delta;
    double eastMin, eastMax;
    double northMin, northMax;

    Ptr<MgCoordinateSystemTransform> gridToFrameXfrom;
    Ptr<MgCoordinateSystemGridBoundary> rgnBoundary;
    Ptr<CCoordinateSystemGridRegion> pMnrRegion;

    MgCoordinateSystemFactory csFactory;
    MgGeometryFactory mgFactory;

    MG_TRY ()
        // This function is in the OneGrid base class.  We call it just in case
        // 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,rK100Km));
        beginEast = static_cast<INT32>(eastMin - ((eastMin >= 0.0) ? delta : (rK100Km - delta)));
        delta = fabs (fmod (eastMax,rK100Km));
        endEast = static_cast<INT32>(eastMax + ((eastMax >= 0.0) ? (rK100Km - delta) : -delta));

        delta = fabs (fmod (northMin,rK100Km));
        beginNorth = static_cast<INT32>(northMin - ((northMin >= 0.0) ? delta : (rK100Km - delta)));
        delta = fabs (fmod (northMax,rK100Km));
        endNorth = static_cast<INT32>(northMax + ((northMax >= 0.0) ? (rK100Km - delta) : -delta));

        // We'll move from south to north, doing each west to east row in turn.
        for (northIndex = beginNorth;northIndex < endNorth;northIndex += iK100Km)
        {
            for (eastIndex = beginEast;eastIndex < endEast;eastIndex += iK100Km)
            {
                Ptr<MgCoordinate> southwest;
                Ptr<MgCoordinate> southeast;
                Ptr<MgCoordinate> northeast;
                Ptr<MgCoordinate> northwest;

                // Use the current eastIndex and northIndex values to generate
                // a 100KM sqaure.
                southwest = mgFactory.CreateCoordinateXY (static_cast<double>(eastIndex),static_cast<double>(northIndex));
                southeast = mgFactory.CreateCoordinateXY (static_cast<double>(eastIndex + iK100Km),static_cast<double>(northIndex));
                northeast = mgFactory.CreateCoordinateXY (static_cast<double>(eastIndex + iK100Km),static_cast<double>(northIndex + iK100Km));
                northwest = mgFactory.CreateCoordinateXY (static_cast<double>(eastIndex),static_cast<double>(northIndex + iK100Km));

                // 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),
                                                                                             static_cast<double>(northIndex + 1),
                                                                                             m_LetteringScheme);
                if (!designation.empty ())
                {
                    // Construct the region object and add it to the region collection.
                    pMnrRegion = new CCoordinateSystemGridRegion (designation);

                    double xx = static_cast<double>(eastIndex + (iK100Km / 2));
                    double yy = static_cast<double>(northIndex + (iK100Km / 2));
                    gridToFrameXfrom->Transform (&xx,&yy);
                    Ptr<MgCoordinate> rgnCenter = mgFactory.CreateCoordinateXY (xx,yy);
                    pMnrRegion->SetRegionCenter (rgnCenter);

                    // Generate the region boundary polygon; then convert to frame coordinates.
                    rgnBoundary = csFactory.GridBoundary (southwest,northeast);
                    rgnBoundary->SetMaxCurvePoints (maxPoints);
                    Ptr<MgPolygon> rgnPolygon = rgnBoundary->GetBoundary (gridToFrameXfrom,curvePrecision);
                    pMnrRegion->SetRegionBoundary (rgnPolygon);

                    // Get a coordinate iterator which represents the grid boundary.
                    // Note, that this boundary is the Intersection of the UTM zone
                    // boundary and the viewport frame boundary.
                    Ptr<MgCoordinateSystemGridBoundary> gridBoundary = GetGridBoundary ();
                    Ptr<MgPolygon> gridPolygon = gridBoundary->GetBoundary ();
                    Ptr<MgLinearRing> gridExteriorRing = gridPolygon->GetExteriorRing ();
                    Ptr<MgCoordinateIterator> gridBoundaryItr = gridExteriorRing->GetCoordinates ();

                    // Generate the four lines.
                    swPntIsIn = MgSpatialUtility::PointIsInPolygon (gridBoundaryItr,southwest);
                    sePntIsIn = MgSpatialUtility::PointIsInPolygon (gridBoundaryItr,southeast);
                    nePntIsIn = MgSpatialUtility::PointIsInPolygon (gridBoundaryItr,northeast);
                    nwPntIsIn = MgSpatialUtility::PointIsInPolygon (gridBoundaryItr,northwest);

                    if (swPntIsIn || sePntIsIn)
                    {
                        Ptr<MgLineString> lineString = gridToFrameXfrom->GridLine (southwest,southeast,curvePrecision,maxPoints);
                        Ptr<MgLineStringCollection> rgnLine = frameBoundary->ClipLineString (lineString);
                        pMnrRegion->SetSouthLine (rgnLine);
                    }
                    if (sePntIsIn || nePntIsIn)
                    {
                        Ptr<MgLineString> lineString = gridToFrameXfrom->GridLine (southeast,northeast,curvePrecision,maxPoints);
                        Ptr<MgLineStringCollection> rgnLine = frameBoundary->ClipLineString (lineString);
                        pMnrRegion->SetEastLine (rgnLine);
                    }
                    if (nePntIsIn || nwPntIsIn)
                    {
                        Ptr<MgLineString> lineString = gridToFrameXfrom->GridLine (northeast,northwest,curvePrecision,maxPoints);
                        Ptr<MgLineStringCollection> rgnLine = frameBoundary->ClipLineString (lineString);
                        pMnrRegion->SetNorthLine (rgnLine);
                    }
                    if (nwPntIsIn || swPntIsIn)
                    {
                        Ptr<MgLineString> lineString = gridToFrameXfrom->GridLine (northwest,southwest,curvePrecision,maxPoints);
                        Ptr<MgLineStringCollection> rgnLine = frameBoundary->ClipLineString (lineString);
                        pMnrRegion->SetWestLine (rgnLine);
                    }

                    regionCollection->Add (pMnrRegion);
                }
            }
        }
    MG_CATCH_AND_THROW(L"MgCoordinateSystemOneGrid::BuildMinorRegions")
}
//////////////////////////////////////////////////////////////////
// Apply the specified set of commands to the map.
//
void c_RestFetchImage::ApplyMapViewCommands(MgMap* map, MgPropertyCollection* mapViewCommands)
{
	if(mapViewCommands == NULL)
		return;

	Ptr<MgProperty> val;

	//Set view center X
	val = mapViewCommands->FindItem(m_mapCmdSetViewCenterX);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetViewCenterX);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		Ptr<MgPoint> center = map->GetViewCenter();
		Ptr<MgCoordinate> coord = center? center->GetCoordinate(): NULL;
		double y = coord? coord->GetY(): 0.;
		MgGeometryFactory gf;
		Ptr<MgCoordinate> coordNewCenter = gf.CreateCoordinateXY(MgUtil::StringToDouble(((MgStringProperty*)((MgProperty*)val))->GetValue()), y);
		Ptr<MgPoint> ptNewCenter = gf.CreatePoint(coordNewCenter);
		map->SetViewCenter(ptNewCenter);
	}

	//Set view center Y
	val = mapViewCommands->FindItem(m_mapCmdSetViewCenterY);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetViewCenterY);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		Ptr<MgPoint> center = map->GetViewCenter();
		Ptr<MgCoordinate> coord = center? center->GetCoordinate(): NULL;
		double x = coord? coord->GetX(): 0.;
		MgGeometryFactory gf;
		Ptr<MgCoordinate> coordNewCenter = gf.CreateCoordinateXY(x, MgUtil::StringToDouble(((MgStringProperty*)((MgProperty*)val))->GetValue()));
		Ptr<MgPoint> ptNewCenter = gf.CreatePoint(coordNewCenter);
		map->SetViewCenter(ptNewCenter);
	}

	//Set view scale
	val = mapViewCommands->FindItem(m_mapCmdSetViewScale);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetViewScale);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		STRING sScale = ((MgStringProperty*)((MgProperty*)val))->GetValue();
		double scale = MgUtil::StringToDouble(sScale);
		if(scale <= 0.0)
		{
			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetViewScale);
			arguments.Add(sScale);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgValueCannotBeLessThanOrEqualToZero", NULL);
		}

		map->SetViewScale(scale);

		//refresh all layers that are visible
		map->SetLayerRefreshMode(MgMap::refreshAll);
	}

	//Set display dpi
	val = mapViewCommands->FindItem(m_mapCmdSetDisplayDpi);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayDpi);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		STRING sDpi = ((MgStringProperty*)((MgProperty*)val))->GetValue();
		INT32 dpi = MgUtil::StringToInt32(sDpi);
		if(dpi <= 0)
		{
			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayDpi);
			arguments.Add(sDpi);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgValueCannotBeLessThanOrEqualToZero", NULL);
		}

		map->SetDisplayDpi(dpi);
	}

	//Set display width
	val = mapViewCommands->FindItem(m_mapCmdSetDisplayWidth);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayWidth);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		STRING sWidth = ((MgStringProperty*)((MgProperty*)val))->GetValue();
		INT32 width = MgUtil::StringToInt32(sWidth);
		if(width <= 0)
		{
			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayWidth);
			arguments.Add(sWidth);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgValueCannotBeLessThanOrEqualToZero", NULL);
		}

		map->SetDisplayWidth(width);
	}

	//Set display height
	val = mapViewCommands->FindItem(m_mapCmdSetDisplayHeight);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayHeight);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		STRING sHeight = ((MgStringProperty*)((MgProperty*)val))->GetValue();
		INT32 height = MgUtil::StringToInt32(sHeight);
		if(height <= 0)
		{
			MgStringCollection arguments;
			arguments.Add(m_mapCmdSetDisplayHeight);
			arguments.Add(sHeight);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgValueCannotBeLessThanOrEqualToZero", NULL);
		}

		map->SetDisplayHeight(height);
	}

	//Show layers
	val = mapViewCommands->FindItem(m_mapCmdShowLayers);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdShowLayers);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		ShowLayers(map, ((MgStringProperty*)((MgProperty*)val))->GetValue(), true);
	}

	//Hide layers
	val = mapViewCommands->FindItem(m_mapCmdHideLayers);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdHideLayers);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		ShowLayers(map, ((MgStringProperty*)((MgProperty*)val))->GetValue(), false);
	}

	//Show groups
	val = mapViewCommands->FindItem(m_mapCmdShowGroups);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdShowGroups);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		ShowGroups(map, ((MgStringProperty*)((MgProperty*)val))->GetValue(), true);
	}

	//Hide groups
	val = mapViewCommands->FindItem(m_mapCmdHideGroups);
	if(val != NULL)
	{
		if(val->GetPropertyType() != MgPropertyType::String)
		{
			STRING buffer;
			MgUtil::Int32ToString((INT32)val->GetPropertyType(), buffer);

			MgStringCollection arguments;
			arguments.Add(m_mapCmdHideGroups);
			arguments.Add(buffer);

			throw new MgInvalidArgumentException(L"MgController.ApplyMapViewCommands",
				__LINE__, __WFILE__, &arguments, L"MgInvalidPropertyTypeForCommand", NULL);
		}

		ShowGroups(map, ((MgStringProperty*)((MgProperty*)val))->GetValue(), false);
	}

	//Refresh layers - applies only to DwfController
}//end of c_RestFetchImage::ApplyMapViewCommands