[mapguide-users] Resample or Clip expression for WMS connection

Sowinski, Keith - DOT Keith.Sowinski at dot.wi.gov
Thu Jun 15 04:54:22 PDT 2023


Thank you Jackie! This is very helpful.

Now I’m getting and Exception when executing the ISelect.  I think it is because lyr.GetFeatureGeometryName() returns an empty string.
[cid:image002.png at 01D99F56.364B5210]

From: mapguide-users <mapguide-users-bounces at lists.osgeo.org> On Behalf Of Jackie Ng
Sent: Wednesday, June 14, 2023 6:45 AM
To: mapguide-users at lists.osgeo.org
Subject: Re: [mapguide-users] Resample or Clip expression for WMS connection


CAUTION: This email originated from outside the organization.
Do not click links or open attachments unless you recognize the sender and know the content is safe.


Actually you're not too far off.

You use the expression capabilities as a programmatic way to answer the question of "What functions I can use for expressions against this particular FDO provider?" by checking if your function of interest (CLIP) is in the collection of supported functions.

If you know in your code that the feature source in question is always pointing to a WMS connection, then you know (from the provider documentation) that CLIP() is supported and you can bypass this capability check. Otherwise, you would use the various capabilities from the root IConnection to ask questions of what this connection can or cannot do.

As for what to do with the command. your CreateCommand call is close, but you are actually supposed to cast that ICommand down to a derived command interface. The ICommand interface itself is pretty barebones and not something you'll ever use directly. The CommandType enum you're passing in is the hint as to what command interface you're actually supposed to cast to.

CommandType.CommandType_Select -> cast the result to ISelect
CommandType.CommandType_DescribeSchema -> cast the result to IDescribeSchema
CommandType.CommandType_SelectAggregates -> cast the result to ISelectAggregates

etc, etc.

Here's a snippet adapted from the "FDO Cookbook - Select Data" example from that devguide link that gives a rough idea of what you're supposed to do once you've created a select command:
// The MgLayerBase has the name of the feature class
Identifier className = new Identifier(lyr.GetFeatureClassName());
// Make the select command
ISelect select = conn.CreateCommand(CommandType.CommandType_Select) as ISelect;
// Set the name of the feature class this select command is querying from
select.FeatureClassName = className;
// The MgLayerBase also knows the name of the designated geometry/raster property for the layer, which you need to know for the first argument of CLIP()
// note the name "clipped_raster", which is our alias for this computed property
ComputedIdentifier computedId = Expression.Parse($"CLIP({lyr.GetFeatureGeometryName()}, {minX}, {minY}, {maxX}, {maxY}) AS clipped_raster") as ComputedIdentifier;
// Add this computed property to the select command
select.PropertyNames.Add(computedId);
// Execute the command
IFeatureReader reader = select.Execute();
// You need to advance the reader in order to get data out of it
try {
    while (reader.ReadNext()) {
        // Access the raster by the computed alias name
        var raster = reader.GetRaster("clipped_raster");
        // TODO: Do something with the raster data
    }
}
finally {
    // Always close the feature readers afterwards when done. Putting this in the finally section of
    // a try/finally block ensures this always happens (regardless of exceptions thrown in the try block)
    reader.Close();
}

You'll need to provide your own minX, minY, maxX, maxY values for the CLIP() function call.

Hope that helps.

- Jackie

You wrote:

I am using Autodesk Civil 3D/Map 3D (contains a MapGuide component) and I need to create a custom command to clip or resample raster image via WMS connection. I am a C# developer.
I see the appropriate expression capabilities listed here, but I cannot find any examples how to apply these expressions to the WMS connection.
FDO Developer's Guide: FDO Provider for WMS Capabilities (autodesk.com)<http://docs.autodesk.com/MAP/2014/ENU/Developer_Guides/index.html>

Can anyone provide an example on how to use expressions? This is what I have so far, but don’t feel like I’m close.

using Autodesk.Gis.Map.Platform;
using OSGeo.FDO.Commands;
using OSGeo.FDO.Connections;
using OSGeo.FDO.Connections.Capabilities;
using OSGeo.FDO.Expression;
using OSGeo.MapGuide;

namespace MapServices
{
    public class WmsLayer
    {
        public static void ClipMapLayer(string layerName)
        {
            AcMapFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as AcMapFeatureService;

            //Get the current Map.
            AcMapMap currentMap = AcMapMap.GetCurrentMap();

            //Get the collecton of Map 3D layers
            MgLayerCollection layers = currentMap.GetLayers();
            if (layers.Contains(layerName)) //Make sure the specified Map 3D layer exists
            {
                //Get the specified Map 3D layer with the Raster image.
                MgLayerBase lyr = layers.GetItem(layerName);

                //Get the resource identifier
                MgResourceIdentifier identifier = new MgResourceIdentifier(lyr.FeatureSourceId);

                //Get the FDO connection from the resource
                IConnection con = fs.GetFdoConnection(identifier);

                //I can get the Expression capabilities from the connection, but what do I do with that??
                IExpressionCapabilities expCaps = con.ExpressionCapabilities;
                ExpressionType[] types = expCaps.ExpressionTypes;
                FunctionDefinitionCollection funcs = expCaps.Functions;

                //Is this how to create the expression?
                //How do I pass the inputs into the expression?
                //How is a BLOB created from the raster?
                Expression wmsCmd = Expression.Parse("CLIP(raster, minX, minY, maxX, maxY)");

                //Do I somehow pass the expression into an ICommand???  No idea what command type is correct.
                ICommand cmd = con.CreateCommand(CommandType.CommandType_Select);
            }
        }
    }
}

Thank you for your assistance!


Keith Sowinski, P.E.
Civil 3D Implementation Engineer
Methods Development Unit
WisDOT Bureau of Project Development
Office: (920) 492-4132
wisconsindot.gov<http://wisconsindot.gov/>



--
Please Note: I no longer create new posts or post replies to any OSGeo mailing list through nabble. As a result, you most likely won't see this message appear on nabble's view of any OSGeo mailing list and may only see this message through mailing list archives or depending on your mailing list subscription settings, through daily message digests or automated notifications from the mailing lists.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20230615/e85f2181/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 53115 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20230615/e85f2181/attachment.png>


More information about the mapguide-users mailing list