[mapguide-commits] r9222 - sandbox/jng/geoprocessing/Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Jun 25 03:36:26 PDT 2017


Author: jng
Date: 2017-06-25 03:36:25 -0700 (Sun, 25 Jun 2017)
New Revision: 9222

Added:
   sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.cpp
   sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.h
   sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.cpp
   sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.h
Log:
Add missing source files from previous commmit

Added: sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.cpp
===================================================================
--- sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.cpp	                        (rev 0)
+++ sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.cpp	2017-06-25 10:36:25 UTC (rev 9222)
@@ -0,0 +1,104 @@
+//
+//  Copyright (C) 2004-2017 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "HttpHandler.h"
+#include "HttpGeoTessellate.h"
+
+HTTP_IMPLEMENT_CREATE_OBJECT(MgHttpGeoTessellate)
+
+MgHttpGeoTessellate::MgHttpGeoTessellate(MgHttpRequest* hRequest)
+{
+    InitializeCommonParameters(hRequest);
+    Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
+    m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
+    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
+    m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
+}
+
+void MgHttpGeoTessellate::Execute(MgHttpResponse & hResponse)
+{
+    Ptr<MgHttpResult> hResult = hResponse.GetResult();
+
+    MG_HTTP_HANDLER_TRY()
+
+    // Check common parameters
+    ValidateCommonParameters();
+
+    if (m_geomWKT.empty())
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqFeatGeometry);
+        arguments.Add(MgResources::BlankArgument);
+
+        throw new MgInvalidArgumentException(L"MgHttpGeoTessellate.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgStringEmpty", NULL);
+    }
+
+    Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+    Ptr<MgGeometry> input = wktRw->Read(m_geomWKT);
+    Ptr<MgGeometry> result = input->Tessellate();
+
+    if (!m_transformTo.empty())
+    {
+        Ptr<MgCoordinateSystemFactory> csFactory = new MgCoordinateSystemFactory();
+        Ptr<MgCoordinateSystem> cs = csFactory->CreateFromCode(m_coordinateSystem);
+        Ptr<MgCoordinateSystem> target = csFactory->CreateFromCode(m_transformTo);
+        Ptr<MgCoordinateSystemTransform> xform = csFactory->GetTransform(cs, target);
+        Ptr<MgGeometry> xGeom = (MgGeometry*)result->Transform(xform);
+
+        result = xGeom;
+    }
+
+    if (m_format == L"WKT")
+    {
+        STRING wkt = wktRw->Write(result);
+        Ptr<MgHttpPrimitiveValue> value = new MgHttpPrimitiveValue(wkt);
+        hResult->SetResultObject(value, MgMimeType::Text);
+    }
+    else if (m_format == L"GEOJSON")
+    {
+        MgGeoJsonWriter gw;
+        STRING geoJson = gw.GeometryToGeoJson(result);
+
+        std::string mbGeoJson;
+        MgUtil::WideCharToMultiByte(geoJson, mbGeoJson);
+
+        Ptr<MgByteSource> byteSource = new MgByteSource((BYTE_ARRAY_IN)mbGeoJson.c_str(), (INT32)mbGeoJson.length());
+        byteSource->SetMimeType(MgMimeType::Json);
+        Ptr<MgByteReader> byteReader = byteSource->GetReader();
+
+        hResult->SetResultObject(byteReader, byteReader->GetMimeType());
+    }
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW_EX(L"MgHttpGeoTessellate.Execute")
+}
+
+void MgHttpGeoTessellate::ValidateOperationVersion()
+{
+    MG_HTTP_HANDLER_TRY()
+
+        // There are multiple supported versions
+        INT32 version = m_userInfo->GetApiVersion();
+    if (version != MG_API_VERSION(3, 3, 0))
+    {
+        throw new MgInvalidOperationVersionException(
+            L"MgHttpGeoTessellate.ValidateOperationVersion", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW(L"MgHttpGeoTessellate.ValidateOperationVersion");
+}

Added: sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.h
===================================================================
--- sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.h	                        (rev 0)
+++ sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeoTessellate.h	2017-06-25 10:36:25 UTC (rev 9222)
@@ -0,0 +1,63 @@
+//
+//  Copyright (C) 2004-2017 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef MG_HTTP_GEO_TESSELLATE_H
+#define MG_HTTP_GEO_TESSELLATE_H
+
+class MgHttpGeoTessellate : public MgHttpRequestResponseHandler
+{
+    HTTP_DECLARE_CREATE_OBJECT()
+
+public:
+    /// <summary>
+    /// Initializes the common parameters of the request.
+    /// </summary>
+    /// <param name="name">Input
+    /// MgHttpRequest
+    /// This contains all the parameters of the request.
+    /// </param>
+    /// <returns>
+    /// nothing
+    /// </returns>
+    MgHttpGeoTessellate(MgHttpRequest *hRequest);
+
+    /// <summary>
+    /// Executes the specific request.
+    /// </summary>
+    /// <param name="hResponse">Input
+    /// This contains the response (including MgHttpResult and StatusCode) from the server.
+    /// </param>
+    void Execute(MgHttpResponse& hResponse);
+
+    /// <summary>
+    /// Returns the classification of this request/response handler
+    /// </summary>
+    /// <returns>
+    /// Classification of handler
+    /// </returns>
+    MgRequestClassification GetRequestClassification() { return MgHttpRequestResponseHandler::mrcViewer; }
+
+    virtual void ValidateOperationVersion();
+
+private:
+    STRING m_geomWKT;
+    STRING m_format;
+    STRING m_coordinateSystem;
+    STRING m_transformTo;
+};
+
+#endif

Added: sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.cpp
===================================================================
--- sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.cpp	                        (rev 0)
+++ sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.cpp	2017-06-25 10:36:25 UTC (rev 9222)
@@ -0,0 +1,161 @@
+//
+//  Copyright (C) 2004-2017 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "HttpHandler.h"
+#include "HttpGeometryInfo.h"
+
+HTTP_IMPLEMENT_CREATE_OBJECT(MgHttpGeometryInfo)
+
+MgHttpGeometryInfo::MgHttpGeometryInfo(MgHttpRequest* hRequest)
+{
+    InitializeCommonParameters(hRequest);
+    Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
+    m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
+}
+
+void MgHttpGeometryInfo::Execute(MgHttpResponse & hResponse)
+{
+    Ptr<MgHttpResult> hResult = hResponse.GetResult();
+
+    MG_HTTP_HANDLER_TRY()
+
+    // Check common parameters
+    ValidateCommonParameters();
+
+    if (m_geomWKT.empty())
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqFeatGeometry);
+        arguments.Add(MgResources::BlankArgument);
+
+        throw new MgInvalidArgumentException(L"MgHttpGeometryInfo.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgStringEmpty", NULL);
+    }
+
+    Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+    Ptr<MgGeometry> input = wktRw->Read(m_geomWKT);
+
+    //Collect all geometry information
+    double area = input->GetArea();
+    INT32 dim = input->GetDimension();
+    double length = input->GetLength();
+    bool isClosed = input->IsClosed();
+    bool isEmpty = input->IsEmpty();
+    bool isSimple = input->IsSimple();
+    bool isValid = input->IsValid();
+    Ptr<MgEnvelope> env = input->Envelope();
+    Ptr<MgPoint> centroid = input->GetCentroid();
+    Ptr<MgCoordinate> cCentroid = centroid->GetCoordinate();
+    Ptr<MgCoordinate> envLL = env->GetLowerLeftCoordinate();
+    Ptr<MgCoordinate> envUR = env->GetUpperRightCoordinate();
+
+    std::string mbXml;
+    mbXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
+    mbXml += "<GeometryInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"GeometryInfo-3.3.0.xsd\">";
+    mbXml += "<Area>";
+    std::string sArea;
+    MgUtil::DoubleToString(area, sArea);
+    mbXml += sArea;
+    mbXml += "</Area>";
+    mbXml += "<Dimension>";
+    std::string sDim;
+    MgUtil::Int32ToString(dim, sDim);
+    mbXml += sDim;
+    mbXml += "</Dimension>";
+    mbXml += "<Length>";
+    std::string sLen;
+    MgUtil::DoubleToString(length, sLen);
+    mbXml += sLen;
+    mbXml += "</Length>";
+    mbXml += "<IsClosed>";
+    mbXml += (isClosed ? "true" : "false");
+    mbXml += "</IsClosed>";
+    mbXml += "<IsEmpty>";
+    mbXml += (isEmpty ? "true" : "false");
+    mbXml += "</IsEmpty>";
+    mbXml += "<IsSimple>";
+    mbXml += (isSimple ? "true" : "false");
+    mbXml += "</IsSimple>";
+    mbXml += "<IsValid>";
+    mbXml += (isValid ? "true" : "false");
+    mbXml += "</IsValid>";
+    mbXml += "<Envelope>";
+    mbXml += "<LowerLeft>";
+    mbXml += "<X>";
+    std::string sLLX;
+    MgUtil::DoubleToString(envLL->GetX(), sLLX);
+    mbXml += sLLX;
+    mbXml += "</X>";
+    mbXml += "<Y>";
+    std::string sLLY;
+    MgUtil::DoubleToString(envLL->GetY(), sLLY);
+    mbXml += sLLY;
+    mbXml += "</Y>";
+    mbXml += "</LowerLeft>";
+    mbXml += "<UpperRight>";
+    mbXml += "<X>";
+    std::string sURX;
+    MgUtil::DoubleToString(envUR->GetX(), sURX);
+    mbXml += sURX;
+    mbXml += "</X>";
+    mbXml += "<Y>";
+    std::string sURY;
+    MgUtil::DoubleToString(envUR->GetY(), sURY);
+    mbXml += sURY;
+    mbXml += "</Y>";
+    mbXml += "</UpperRight>";
+    mbXml += "</Envelope>";
+    mbXml += "<Centroid>";
+    mbXml += "<X>";
+    std::string sCentX;
+    MgUtil::DoubleToString(cCentroid->GetX(), sCentX);
+    mbXml += sCentX;
+    mbXml += "</X>";
+    mbXml += "<Y>";
+    std::string sCentY;
+    MgUtil::DoubleToString(cCentroid->GetY(), sCentY);
+    mbXml += sCentY;
+    mbXml += "</Y>";
+    mbXml += "</Centroid>";
+    mbXml += "</GeometryInfo>";
+
+    Ptr<MgByteSource> bs = new MgByteSource((BYTE_ARRAY_IN)mbXml.c_str(), (INT32)mbXml.length());
+    bs->SetMimeType(MgMimeType::Xml);
+    Ptr<MgByteReader> br = bs->GetReader();
+
+    //Convert to alternate response format, if necessary
+    ProcessFormatConversion(br);
+
+    hResult->SetResultObject(br, br->GetMimeType());
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW_EX(L"MgHttpGeometryInfo.Execute")
+}
+
+void MgHttpGeometryInfo::ValidateOperationVersion()
+{
+    MG_HTTP_HANDLER_TRY()
+
+    // There are multiple supported versions
+    INT32 version = m_userInfo->GetApiVersion();
+    if (version != MG_API_VERSION(3, 3, 0))
+    {
+        throw new MgInvalidOperationVersionException(
+            L"MgHttpGeometryInfo.ValidateOperationVersion", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW(L"MgHttpGeometryInfo.ValidateOperationVersion");
+}

Added: sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.h
===================================================================
--- sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.h	                        (rev 0)
+++ sandbox/jng/geoprocessing/Web/src/HttpHandler/HttpGeometryInfo.h	2017-06-25 10:36:25 UTC (rev 9222)
@@ -0,0 +1,60 @@
+//
+//  Copyright (C) 2004-2017 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef MG_HTTP_GEOMETRY_INFO_H
+#define MG_HTTP_GEOMETRY_INFO_H
+
+class MgHttpGeometryInfo : public MgHttpRequestResponseHandler
+{
+    HTTP_DECLARE_CREATE_OBJECT()
+
+public:
+    /// <summary>
+    /// Initializes the common parameters of the request.
+    /// </summary>
+    /// <param name="name">Input
+    /// MgHttpRequest
+    /// This contains all the parameters of the request.
+    /// </param>
+    /// <returns>
+    /// nothing
+    /// </returns>
+    MgHttpGeometryInfo(MgHttpRequest *hRequest);
+
+    /// <summary>
+    /// Executes the specific request.
+    /// </summary>
+    /// <param name="hResponse">Input
+    /// This contains the response (including MgHttpResult and StatusCode) from the server.
+    /// </param>
+    void Execute(MgHttpResponse& hResponse);
+
+    /// <summary>
+    /// Returns the classification of this request/response handler
+    /// </summary>
+    /// <returns>
+    /// Classification of handler
+    /// </returns>
+    MgRequestClassification GetRequestClassification() { return MgHttpRequestResponseHandler::mrcViewer; }
+
+    virtual void ValidateOperationVersion();
+
+private:
+    STRING m_geomWKT;
+};
+
+#endif



More information about the mapguide-commits mailing list