[mapguide-commits] r6379 - in
trunk/MgDev/Doc/samples/dotnetsamples: analyzing_features
modifying_maps_and_layers
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Dec 29 06:45:05 EST 2011
Author: jng
Date: 2011-12-29 03:45:05 -0800 (Thu, 29 Dec 2011)
New Revision: 6379
Added:
trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/bufferfunctions.aspx
trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/createbuffer.aspx
trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/selectfeaturesinbuffer.aspx
trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/task_pane.aspx
Modified:
trunk/MgDev/Doc/samples/dotnetsamples/modifying_maps_and_layers/layer_functions.aspx
Log:
Dev Guide: Add buffering example (.net)
Added: trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/bufferfunctions.aspx
===================================================================
--- trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/bufferfunctions.aspx (rev 0)
+++ trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/bufferfunctions.aspx 2011-12-29 11:45:05 UTC (rev 6379)
@@ -0,0 +1,200 @@
+<%--
+ Copyright (C) 2004-2011 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
+--%>
+<%@ Import Namespace="System" %>
+<%@ Import Namespace="System.Xml" %>
+<%@ Import Namespace="OSGeo.MapGuide" %>
+<!-- #Include File="../common/common.aspx" -->
+<script language="C#" runat="server">
+
+ public class BufferHelper
+ {
+ private HttpServerUtility _server;
+
+ public BufferHelper(HttpServerUtility server)
+ {
+ _server = server;
+ }
+
+ HttpServerUtility Server { get { return _server; } }
+
+ public void CreateBufferFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier bufferFeatureResId)
+ {
+ MgClassDefinition bufferClass = new MgClassDefinition();
+ bufferClass.SetName("BufferClass");
+ MgPropertyDefinitionCollection properties = bufferClass.GetProperties();
+
+ MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
+ idProperty.SetDataType(MgPropertyType.Int32);
+ idProperty.SetReadOnly(true);
+ idProperty.SetNullable(false);
+ idProperty.SetAutoGeneration(true);
+ properties.Add(idProperty);
+
+ MgGeometricPropertyDefinition polygonProperty = new MgGeometricPropertyDefinition("BufferGeometry");
+ polygonProperty.SetGeometryTypes(MgFeatureGeometricType.Surface);
+ polygonProperty.SetHasElevation(false);
+ polygonProperty.SetHasMeasure(false);
+ polygonProperty.SetReadOnly(false);
+ polygonProperty.SetSpatialContextAssociation("defaultSrs");
+ properties.Add(polygonProperty);
+
+ MgPropertyDefinitionCollection idProperties = bufferClass.GetIdentityProperties();
+ idProperties.Add(idProperty);
+
+ bufferClass.SetDefaultGeometryPropertyName("BufferGeometry");
+
+ MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", "temporary schema to hold a buffer");
+ bufferSchema.GetClasses().Add(bufferClass);
+
+ MgCreateSdfParams sdfParams = new MgCreateSdfParams("defaultSrs", wkt, bufferSchema);
+
+ featureService.CreateFeatureSource(bufferFeatureResId, sdfParams);
+ }
+
+ public MgLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
+ {
+ // Load the layer definition template into
+ // a XmlDocument object, find the "ResourceId" element, and
+ // modify its content to reference the temporary
+ // feature source.
+
+ XmlDocument doc = new XmlDocument();
+ doc.Load(Server.MapPath("bufferlayerdefinition.xml"));
+ XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];
+ featureSourceNode.InnerText = bufferFeatureResId.ToString();
+
+ // Get the updated layer definition from the XmlDocument
+ // and save it to the session repository using the
+ // ResourceService object.
+
+ MgByteSource byteSource = null;
+ using (MemoryStream ms = new MemoryStream())
+ {
+ doc.Save(ms);
+ ms.Position = 0L;
+
+ //Note we do this to ensure our XML content is free of any BOM characters
+ byte [] layerDefinition = ms.ToArray();
+ Encoding utf8 = Encoding.UTF8;
+ String layerDefStr = new String(utf8.GetChars(layerDefinition));
+ layerDefinition = new byte[layerDefStr.Length-1];
+ int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length-1, layerDefinition, 0);
+
+ byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
+ byteSource.SetMimeType(MgMimeType.Xml);
+ }
+
+ MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");
+
+ resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);
+
+ // Create an MgLayer object based on the new layer definition
+ // and return it to the caller.
+
+ MgLayer bufferLayer = new MgLayer(tempLayerResId, resourceService);
+ bufferLayer.SetName("Buffer");
+ bufferLayer.SetLegendLabel("Buffer");
+ bufferLayer.SetDisplayInLegend(true);
+ bufferLayer.SetSelectable(false);
+
+ return bufferLayer;
+ }
+
+ public void CreateParcelMarkerFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier parcelMarkerDataResId)
+ {
+ MgClassDefinition parcelClass = new MgClassDefinition();
+ parcelClass.SetName("ParcelMarkerClass");
+ MgPropertyDefinitionCollection properties = parcelClass.GetProperties();
+
+ MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
+ idProperty.SetDataType(MgPropertyType.Int32);
+ idProperty.SetReadOnly(true);
+ idProperty.SetNullable(false);
+ idProperty.SetAutoGeneration(true);
+ properties.Add(idProperty);
+
+ MgGeometricPropertyDefinition pointProperty = new MgGeometricPropertyDefinition("ParcelLocation");
+ pointProperty.SetGeometryTypes(MgGeometryType.Point);
+ pointProperty.SetHasElevation(false);
+ pointProperty.SetHasMeasure(false);
+ pointProperty.SetReadOnly(false);
+ pointProperty.SetSpatialContextAssociation("defaultSrs");
+ properties.Add(pointProperty);
+
+ MgPropertyDefinitionCollection idProperties = parcelClass.GetIdentityProperties();
+ idProperties.Add(idProperty);
+
+ parcelClass.SetDefaultGeometryPropertyName("ParcelLocation");
+
+ MgFeatureSchema parcelSchema = new MgFeatureSchema("ParcelLayerSchema", "temporary schema to hold parcel markers");
+ parcelSchema.GetClasses().Add(parcelClass);
+
+ MgCreateSdfParams sdfParams = new MgCreateSdfParams("defaultSrs", wkt, parcelSchema);
+
+ featureService.CreateFeatureSource(parcelMarkerDataResId, sdfParams);
+ }
+
+ public MgLayer CreateParcelMarkerLayer(MgResourceService resourceService, MgResourceIdentifier parcelMarkerDataResId, String sessionId)
+ {
+ // Load the ParcelMarker layer definition template into
+ // a XmlDocument object, find the "ResourceId" element, and
+ // modify its content to reference the temporary
+ // feature source.
+
+ XmlDocument doc = new XmlDocument();
+ doc.Load(Server.MapPath("parcelmarker.xml"));
+ XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];
+ featureSourceNode.InnerText = parcelMarkerDataResId.ToString();
+
+ // Get the updated layer definition from the DOM object
+ // and save it to the session repository using the
+ // ResourceService object.
+
+ MgByteSource byteSource = null;
+ using (MemoryStream ms = new MemoryStream())
+ {
+ doc.Save(ms);
+ ms.Position = 0L;
+
+ //Note we do this to ensure our XML content is free of any BOM characters
+ byte [] layerDefinition = ms.ToArray();
+ Encoding utf8 = Encoding.UTF8;
+ String layerDefStr = new String(utf8.GetChars(layerDefinition));
+ layerDefinition = new byte[layerDefStr.Length-1];
+ int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length-1, layerDefinition, 0);
+
+ byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
+ byteSource.SetMimeType(MgMimeType.Xml);
+ }
+
+ MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.LayerDefinition");
+
+ resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);
+
+ // Create an MgLayer object based on the new layer definition
+ // and return it to the caller.
+
+ MgLayer parcelMarkerLayer = new MgLayer(tempLayerResId, resourceService);
+ parcelMarkerLayer.SetName("ParcelMarker");
+ parcelMarkerLayer.SetLegendLabel("ParcelMarker");
+ parcelMarkerLayer.SetDisplayInLegend(true);
+ parcelMarkerLayer.SetSelectable(false);
+
+ return parcelMarkerLayer;
+ }
+ }
+
+</script>
\ No newline at end of file
Added: trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/createbuffer.aspx
===================================================================
--- trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/createbuffer.aspx (rev 0)
+++ trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/createbuffer.aspx 2011-12-29 11:45:05 UTC (rev 6379)
@@ -0,0 +1,200 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 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
+-->
+<!--
+This sample has been updated to reflect simplified usage patterns enabled by convenience APIs
+introduced in MapGuide OS 2.0 by allowing you to query and insert features directly from
+the MgLayer objects themselves and the ability to get a MgFeatureReader directly from the MgSelection
+object
+-->
+
+<%@ Page Language="c#" %>
+
+<%@ Import Namespace="System" %>
+<%@ Import Namespace="System.Collections.Specialized" %>
+<%@ Import Namespace="System.IO" %>
+<%@ Import Namespace="OSGeo.MapGuide" %>
+
+<script runat="server">
+ String sessionId;
+ String mapName;
+</script>
+
+<!-- #Include File="bufferfunctions.aspx" -->
+<html>
+<head>
+ <title>Viewer Sample Application - Create Buffer</title>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <meta http-equiv="content-script-type" content="text/javascript" />
+ <meta http-equiv="content-style-type" content="text/css" />
+ <link href="../styles/globalStyles.css" rel="stylesheet" type="text/css">
+ <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
+
+ <script language="javascript">
+ function OnPageLoad() {
+ parent.parent.Refresh();
+ }
+ </script>
+
+</head>
+<body class="AppFrame" onload="OnPageLoad()">
+ <h1 class="AppHeading">Create buffer</h1>
+ <%
+ sessionId = Request.Params["SESSION"];
+ mapName = Request.Params["MAPNAME"];
+ String selectionXml = HttpUtility.UrlDecode(Request.Params["SELECTION"]);
+
+ try
+ {
+ // Initialize the Web Extensions and connect to the Server using
+ // the Web Extensions session identifier stored in PHP session state.
+
+ MapGuideApi.MgInitializeWebTier(Constants.WebConfigPath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.Open(userInfo);
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
+ MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
+
+ MgMap map = new MgMap(siteConnection);
+ map.Open(mapName);
+
+ // Check for selection data passed via HTTP POST
+
+ MgSelection selection = null;
+ MgReadOnlyLayerCollection selectedLayers = null;
+ if (!string.IsNullOrEmpty(selectionXml))
+ {
+ selection = new MgSelection(map, selectionXml);
+ selectedLayers = selection.GetLayers();
+ }
+
+ if (selectedLayers != null)
+ {
+ int bufferRingSize = 100; // measured in metres
+ int bufferRingCount = 5;
+
+ // Set up some objects for coordinate conversion
+
+ String mapWktSrs = map.GetMapSRS();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
+ MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
+ MgCoordinateSystem srs = coordinateSystemFactory.Create(mapWktSrs);
+ MgMeasure srsMeasure = srs.GetMeasure();
+
+ BufferHelper helper = new BufferHelper(Server);
+
+ // Check for a buffer layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the buffer.
+
+ MgLayer bufferLayer = null;
+ int layerIndex = map.GetLayers().IndexOf("Buffer");
+ if (layerIndex < 0)
+ {
+ // The layer does not exist and must be created.
+
+ MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
+ helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
+ bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
+ map.GetLayers().Insert(0, bufferLayer);
+ }
+ else
+ {
+ bufferLayer = (MgLayer)map.GetLayers().GetItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.Add(new MgDeleteFeatures("BufferClass", "ID like '%'"));
+
+ bufferLayer.UpdateFeatures(commands);
+ }
+
+ for (int i = 0; i < selectedLayers.GetCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+
+ MgLayer layer = (MgLayer)selectedLayers.GetItem(i);
+
+ if (layer.GetName() == "Parcels")
+ {
+ // Get the selected features from the MgSelection object
+ MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);
+
+ // Process each item in the MgFeatureReader. Get the
+ // geometries from all the selected features and
+ // merge them into a single geometry.
+
+ MgGeometryCollection inputGeometries = new MgGeometryCollection();
+ while (featureReader.ReadNext())
+ {
+ MgByteReader featureGeometryData = featureReader.GetGeometry("SHPGEOM");
+ MgGeometry featureGeometry = agfReaderWriter.Read(featureGeometryData);
+
+ inputGeometries.Add(featureGeometry);
+ }
+
+ MgGeometryFactory geometryFactory = new MgGeometryFactory();
+ MgGeometry mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);
+
+ // Add buffer features to the temporary feature source.
+ // Create multiple concentric buffers to show area.
+ // If the stylization for the layer draws the features
+ // partially transparent, the concentric rings will be
+ // progressively darker towards the center.
+ // The stylization is set in the layer template file, which
+ // is used in function CreateBufferLayer().
+
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++)
+ {
+ double bufferDist = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1));
+ MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);
+
+ MgPropertyCollection properties = new MgPropertyCollection();
+ properties.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
+
+ commands.Add(new MgInsertFeatures("BufferClass", properties));
+ }
+
+ bufferLayer.UpdateFeatures(commands);
+
+ bufferLayer.SetVisible(true);
+ bufferLayer.ForceRefresh();
+ bufferLayer.SetDisplayInLegend(true);
+ map.Save();
+
+ }
+ }
+ }
+ else
+ Response.Write("No selected layers");
+ Response.Write("</p>");
+
+ }
+ catch (MgException e)
+ {
+ Response.Write("<p>" + e.GetExceptionMessage() + "</p>");
+ Response.Write("<p>" + e.GetDetails() + "</p>");
+ }
+ %>
+ <p>The buffer has been created.</p>
+</body>
+</html>
Added: trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/selectfeaturesinbuffer.aspx
===================================================================
--- trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/selectfeaturesinbuffer.aspx (rev 0)
+++ trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/selectfeaturesinbuffer.aspx 2011-12-29 11:45:05 UTC (rev 6379)
@@ -0,0 +1,268 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 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
+-->
+<!--
+This sample has been updated to reflect simplified usage patterns enabled by convenience APIs
+introduced in MapGuide OS 2.0 by allowing you to query and insert features directly from
+the MgLayer objects themselves and the ability to get a MgFeatureReader directly from the MgSelection
+object.
+-->
+
+<%@ Page Language="c#" %>
+
+<%@ Import Namespace="System" %>
+<%@ Import Namespace="System.Collections.Specialized" %>
+<%@ Import Namespace="System.IO" %>
+<%@ Import Namespace="OSGeo.MapGuide" %>
+
+<script runat="server">
+ String sessionId;
+ String mapName;
+</script>
+
+<!-- #Include File="bufferfunctions.aspx" -->
+<html>
+<head>
+ <title>Viewer Sample Application - Select Within Buffer</title>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <meta http-equiv="content-script-type" content="text/javascript" />
+ <meta http-equiv="content-style-type" content="text/css" />
+ <link href="../styles/globalStyles.css" rel="stylesheet" type="text/css">
+ <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
+
+ <script language="javascript">
+ function OnPageLoad() {
+ parent.parent.Refresh();
+ }
+ </script>
+
+</head>
+<body class="AppFrame" onload="OnPageLoad()">
+ <h1 class="AppHeading">
+ Select within buffer area</h1>
+ <%
+
+ sessionId = Request.Params["SESSION"];
+ mapName = Request.Params["MAPNAME"];
+ String selectionXml = HttpUtility.UrlDecode(Request.Params["SELECTION"]);
+
+ try
+ {
+ // Initialize the Web Extensions and connect to the Server using
+ // the Web Extensions session identifier stored in PHP session state.
+
+ MapGuideApi.MgInitializeWebTier (Constants.WebConfigPath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.Open(userInfo);
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
+ MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
+
+ MgMap map = new MgMap(siteConnection);
+ map.Open(mapName);
+
+ // Check for selection data passed via HTTP POST
+
+ MgSelection selection = null;
+ MgReadOnlyLayerCollection selectedLayers = null;
+ if (!string.IsNullOrEmpty(selectionXml))
+ {
+ selection = new MgSelection(map, selectionXml);
+ selectedLayers = selection.GetLayers();
+ }
+
+ if (selectedLayers != null)
+ {
+ int bufferRingSize = 500; // measured in metres
+
+ // Set up some objects for coordinate conversion
+
+ String mapWktSrs = map.GetMapSRS();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
+ MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
+ MgCoordinateSystem srs = coordinateSystemFactory.Create(mapWktSrs);
+ MgMeasure srsMeasure = srs.GetMeasure();
+
+ // Check for a buffer layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the buffer.
+
+ BufferHelper helper = new BufferHelper(Server);
+ MgLayer bufferLayer = null;
+ int layerIndex = map.GetLayers().IndexOf("Buffer");
+ if (layerIndex < 0)
+ {
+ // The layer does not exist and must be created.
+
+ MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
+ helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
+ bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
+ map.GetLayers().Insert(0, bufferLayer);
+ }
+ else
+ {
+ bufferLayer = (MgLayer)map.GetLayers().GetItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.Add(new MgDeleteFeatures("BufferClass", "ID like '%'"));
+
+ bufferLayer.UpdateFeatures(commands);
+ }
+
+ // Check for a parcel marker layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the parcel markers.
+
+ MgLayer parcelMarkerLayer = null;
+ layerIndex = map.GetLayers().IndexOf("ParcelMarker");
+ if (layerIndex < 0)
+ {
+ MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
+ helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
+ parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
+ map.GetLayers().Insert(0, parcelMarkerLayer);
+ }
+ else
+ {
+ parcelMarkerLayer = (MgLayer)map.GetLayers().GetItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.Add(new MgDeleteFeatures("ParcelMarkerClass", "ID like '%'"));
+
+ parcelMarkerLayer.UpdateFeatures(commands);
+ }
+
+ // Check each layer in the selection.
+
+ for (int i = 0; i < selectedLayers.GetCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+
+ MgLayer layer = (MgLayer)selectedLayers.GetItem(i);
+
+ if (layer.GetName() == "Parcels")
+ {
+
+ Response.Write( "Marking all parcels inside the buffer that are of type 'MFG'");
+
+ MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);
+
+
+ // Process each item in the MgFeatureReader. Get the
+ // geometries from all the selected features and
+ // merge them into a single geometry.
+
+ MgGeometryCollection inputGeometries = new MgGeometryCollection();
+ while (featureReader.ReadNext())
+ {
+ MgByteReader featureGeometryData = featureReader.GetGeometry("SHPGEOM");
+ MgGeometry featureGeometry = agfReaderWriter.Read(featureGeometryData);
+
+ inputGeometries.Add(featureGeometry);
+ }
+
+ MgGeometryFactory geometryFactory = new MgGeometryFactory();
+ MgGeometry mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);
+
+ // Create a buffer from the merged geometries
+
+ double bufferDist = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize);
+ MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);
+
+ // Create a filter to select parcels within the buffer. Combine
+ // a basic filter and a spatial filter to select all parcels
+ // within the buffer that are of type "MFG".
+
+ queryOptions = new MgFeatureQueryOptions();
+ queryOptions.SetFilter("RTYPE = 'MFG'");
+ queryOptions.SetSpatialFilter("SHPGEOM", bufferGeometry, MgFeatureSpatialOperations.Inside);
+
+ featureReader = layer.SelectFeatures(queryOptions);
+
+ // Get the features from the feature source,
+ // determine the centroid of each selected feature, and
+ // add a point to the ParcelMarker layer to mark the
+ // centroid.
+ // Collect all the points into an MgFeatureCommandCollection,
+ // so they can all be added in one operation.
+
+ MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
+ while (featureReader.ReadNext())
+ {
+ MgByteReader byteReader = featureReader.GetGeometry("SHPGEOM");
+ MgGeometry geometry = agfReaderWriter.Read(byteReader);
+ MgPoint point = geometry.GetCentroid();
+
+ // Create an insert command for this parcel.
+ MgPropertyCollection properties = new MgPropertyCollection();
+ properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point)));
+ parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties));
+ }
+ featureReader.Close();
+
+ if (parcelMarkerCommands.GetCount() > 0)
+ {
+ parcelMarkerLayer.UpdateFeatures(parcelMarkerCommands);
+ }
+ else
+ {
+ Response.Write("</p><p>No parcels within the buffer area match.");
+ }
+
+ // Create a feature in the buffer feature source to show the area covered by the buffer.
+
+ MgPropertyCollection props = new MgPropertyCollection();
+ props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
+
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.Add(new MgInsertFeatures("BufferClass", props));
+
+ bufferLayer.UpdateFeatures(commands);
+
+ // Ensure that the buffer layer is visible and in the legend.
+
+ bufferLayer.SetVisible(true);
+ bufferLayer.ForceRefresh();
+ bufferLayer.SetDisplayInLegend(true);
+ parcelMarkerLayer.SetVisible(true);
+ parcelMarkerLayer.ForceRefresh();
+
+ map.Save();
+
+ }
+ }
+ }
+ else
+ {
+ Response.Write( "No selected layers");
+ Response.Write( "</p>");
+ }
+
+ }
+ catch (MgException e)
+ {
+ Response.Write( "<p>" + e.GetExceptionMessage() + "</p>");
+ Response.Write( "<p>" + e.GetDetails() + "</p>");
+ }
+ %>
+ <p>Done.</p>
+</body>
+</html>
Copied: trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/task_pane.aspx (from rev 6363, trunk/MgDev/Doc/samples/dotnetsamples/working_with_feature_data/task_pane.aspx)
===================================================================
--- trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/task_pane.aspx (rev 0)
+++ trunk/MgDev/Doc/samples/dotnetsamples/analyzing_features/task_pane.aspx 2011-12-29 11:45:05 UTC (rev 6379)
@@ -0,0 +1,101 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 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
+-->
+<%@ Page language="c#" %>
+<%@ Import Namespace="System" %>
+<script runat="server">
+String sessionId;
+String mapName;
+String fullPath;
+</script>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <meta http-equiv="content-script-type" content="text/javascript">
+ <meta http-equiv="content-style-type" content="text/css">
+ <link href="../styles/globalStyles.css" rel="stylesheet" type="text/css">
+ <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
+ <script language=javascript>
+ function submitBufferRequest(pageUrl)
+ {
+ xmlSel = parent.parent.mapFrame.GetSelectionXML();
+ if (xmlSel.length > 0)
+ {
+ params = new Array("SESSION", parent.parent.mapFrame.GetSessionId(),
+ "MAPNAME", parent.parent.mapFrame.GetMapName(),
+ "SELECTION", encodeURIComponent(xmlSel));
+ parent.parent.formFrame.Submit(pageUrl, params, "taskPaneFrame");
+ }
+ else {
+ alert ("Please select a parcel");
+ }
+ }
+
+ function OnPageLoad()
+ {
+ parent.parent.mapFrame.Refresh();
+ parent.parent.mapFrame.ZoomToScale(9999);
+ }
+ </script>
+ </head>
+ <body onLoad="OnPageLoad()" class="AppFrame">
+ <h1 class="AppHeading">Analyzing Features</h1>
+ <%
+ sessionId = Request.Params["SESSION"];
+ mapName = Request.Params["MAPNAME"];
+ %>
+ <ul>
+ <li>
+ <a href="#" onClick="submitBufferRequest('../dotnetsamples/analyzing_features/createbuffer.aspx'); return false;">
+ Create buffer</a>
+ <br/>Create a buffer around a selected parcel.
+ <br/>
+ <%
+ fullPath = Server.MapPath("createbuffer.aspx");
+ %>
+ <a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath %>" >View source</a>
+ </li>
+
+ <li>
+ <a href="#" onClick="submitBufferRequest('../dotnetsamples/analyzing_features/selectfeaturesinbuffer.aspx'); return false;">
+ Find features in buffer</a>
+ <br/>Create a buffer around a selected parcel, then mark parcels inside the buffer that are
+ of type "MFG".
+ <br/>
+ <%
+ fullPath = Server.MapPath("selectfeaturesinbuffer.aspx");
+ %>
+ <a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath %>" >View source</a>
+ </li>
+
+ </ul>
+
+ <p>View source for support files:</p>
+ <%
+ fullPath = Server.MapPath("task_pane.aspx");
+ String fullPath2 = Server.MapPath("bufferfunctions.aspx");
+ String fullPath3 = Server.MapPath("bufferlayerdefinition.xml");
+ String fullPath4 = Server.MapPath("parcelmarker.xml");
+ %>
+ <ul>
+ <li><a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath %>">task_pane.aspx</a></li>
+ <li><a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath2 %>">bufferfunctions.aspx</a></li>
+ <li><a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath3 %>">bufferlayerdefinition.xml</a></li>
+ <li><a target="_blank" href="../common/viewsource.aspx?FILENAME=<%= fullPath4 %>">parcelmarker.xml</a></li>
+ </ul>
+ </body>
+</html>
Modified: trunk/MgDev/Doc/samples/dotnetsamples/modifying_maps_and_layers/layer_functions.aspx
===================================================================
--- trunk/MgDev/Doc/samples/dotnetsamples/modifying_maps_and_layers/layer_functions.aspx 2011-12-29 10:48:17 UTC (rev 6378)
+++ trunk/MgDev/Doc/samples/dotnetsamples/modifying_maps_and_layers/layer_functions.aspx 2011-12-29 11:45:05 UTC (rev 6379)
@@ -1,4 +1,3 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%--
Copyright (C) 2004-2011 by Autodesk, Inc.
This library is free software; you can redistribute it and/or
More information about the mapguide-commits
mailing list