private CustomLayerInfos GetLayerInfos() { IMapServer3 mapServer = serverObjectHelper.ServerObject as IMapServer3; if (mapServer == null) { throw new Exception("Unable to access the map server."); } IMapServerInfo msInfo = mapServer.GetServerInfo(mapServer.DefaultMapName); IMapLayerInfos layerInfos = msInfo.MapLayerInfos; int c = layerInfos.Count; CustomLayerInfos customLayerInfos = new CustomLayerInfos(Constants.SOENamespaceURI); for (int i = 0; i < c; i++) { IMapLayerInfo layerInfo = layerInfos.get_Element(i); CustomLayerInfo customLayerInfo = new CustomLayerInfo(); customLayerInfo.Name = layerInfo.Name; customLayerInfo.ID = layerInfo.ID; customLayerInfo.Extent = layerInfo.Extent; customLayerInfos.Add(customLayerInfo); } return(customLayerInfos); }
public QueryRasterLayer(IMapLayerInfo mapLayerInfo, IRaster raster) { this.Name = mapLayerInfo.Name; this.ID = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; this.Raster = raster; }
/// <summary> /// Locates the map layer that matches the supplied name. /// </summary> /// <param name="serverObject"></param> /// <param name="layerName"></param> /// <returns></returns> public static IMapLayerInfo FindLayer(this ESRI.ArcGIS.Server.IServerObject serverObject, string layerName) { // Get the list of layers var mapServer = serverObject as IMapServer3; if (mapServer == null) { return(null); } IMapLayerInfos mapLayerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos; for (int i = 0; i < mapLayerInfos.Count; i++) { IMapLayerInfo layer = mapLayerInfos.get_Element(i); if (layer == null || !layer.IsFeatureLayer || !string.Equals(layer.Name, layerName)) { continue; } return(layer); } return(null); }
/// <summary> /// From service fills list of layer with M /// </summary> private void GetRouteLayerInfos() { IMapServer3 serverObject = this.GetMapServer(); IMapLayerInfos mapLayerInfos = serverObject.GetServerInfo(serverObject.DefaultMapName).MapLayerInfos; this.routeLayerInfos = new List <RouteLayerInfo>(); for (int i = 0; i < mapLayerInfos.Count; i++) { IMapLayerInfo mapLayerInfo = mapLayerInfos.get_Element(i); if (mapLayerInfo.IsFeatureLayer) { IFields fields = mapLayerInfo.Fields; for (int j = 0; j < fields.FieldCount; j++) { IField field = fields.get_Field(j); if (field.Type == esriFieldType.esriFieldTypeGeometry) { IGeometryDef geometryDef = field.GeometryDef; if (geometryDef.HasM) { this.routeLayerInfos.Add(new RouteLayerInfo(mapLayerInfo)); } break; } } } } }
public void Init(IServerObjectHelper pSOH) { serverObjectHelper = pSOH; mapService = (MapServer)serverObjectHelper.ServerObject; mapServerDataAccess = (IMapServerDataAccess)serverObjectHelper.ServerObject; // Check if this service contains a Utility Network layer unLayerInfo = soeUtil.GetUNLayerInfo(mapService); if (unLayerInfo != null) { // Get the Utility Network dataset IFeatureClass fc = (IFeatureClass)mapServerDataAccess.GetDataSource(mapService.DefaultMapName, unLayerInfo.SubLayers.Element[0]); // Get UN dataset IFeatureDataset fd = fc.FeatureDataset; IDataset ds = (IDataset)fd; IEnumDataset enumSubDS = ds.Subsets; IDataset subDS = enumSubDS.Next(); while (subDS != null) { if (subDS.Type == esriDatasetType.esriDTUtilityNetwork) { unDataset = subDS; break; } subDS = enumSubDS.Next(); } logger.LogMessage(ServerLogger.msgType.infoStandard, soe_name + ".init()", 200, "UN dataset found: " + unDataset.Name); } }
public CustomLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.Type = mapLayerInfo.Type; this.ID = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; this.Description = mapLayerInfo.Description; }
public CustomLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.Type = mapLayerInfo.Type; this.ID = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; this.Description = mapLayerInfo.Description; }
public void Construct(IPropertySet props) { configProps = props; string lid = (string)props.GetProperty("layerId"); this.layerId = Convert.ToInt32(lid); this.fc = (IFeatureClass)this.mapServerDataAccess.GetDataSource(this.mapServerInfo.Name, this.layerId); this.editLayerInfo = this.layerInfos.get_Element(this.layerId); }
public NetUNTracingRESTSOE() { soe_name = this.GetType().Name; logger = new ServerLogger(); reqHandler = new SoeRestImpl(soe_name, CreateRestSchema()) as IRESTRequestHandler; soeUtil = new SOEUtil(); mapService = null; unLayerInfo = null; mapServerDataAccess = null; unDataset = null; }
private bool loadGeometricNetworkFromServer(IServerObjectHelper serverObjectHelper, ServerLogger logger) { bool result = false; if (null != serverObjectHelper) { try { IMapServer3 mapServer = (IMapServer3)serverObjectHelper.ServerObject; IMapServerDataAccess da = (IMapServerDataAccess)mapServer; IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos; IFeatureDataset ftrDataset = null; for (int i = 0; i < layerInfos.Count; i++) { IMapLayerInfo lyrInfo = layerInfos.get_Element(i); if (lyrInfo.IsFeatureLayer) { IFeatureClass ftrClass = (IFeatureClass)da.GetDataSource(mapServer.DefaultMapName, lyrInfo.ID); if (null == ftrDataset && ftrClass.FeatureDataset.Name == this.networkName) { ftrDataset = ftrClass.FeatureDataset; } if (esriFeatureType.esriFTSimpleEdge == ftrClass.FeatureType) { this.addEdgeFeatureClass(ftrClass); } else if (esriFeatureType.esriFTSimpleJunction == ftrClass.FeatureType) { this.addJunctionFeatureClass(ftrClass); } } } if (this.edgeCount > 0 && this.junctionCount > 0 && null != ftrDataset) { INetworkCollection networkCollection = ftrDataset as INetworkCollection; if (networkCollection != null && networkCollection.GeometricNetworkCount > 0) { this.geometricNetwork = networkCollection.GeometricNetwork[0]; result = true; } } } catch (Exception e) { if (null != logger) { logger.LogMessage(ServerLogger.msgType.error, typeof(NetworkHelper).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, GLC.AO.AOUtilities.ErrorCode, e.Message); } } } return(result); }
private CustomLayerInfo[] GetLayerInfos() { int c = this.layerInfos.Count; CustomLayerInfo[] customLayerInfos = new CustomLayerInfo[c]; for (int i = 0; i < c; i++) { IMapLayerInfo layerInfo = layerInfos.get_Element(i); customLayerInfos[i] = new CustomLayerInfo(layerInfo); } return(customLayerInfos); }
/** * This method returns the layer id of the layer matching the specified name */ public int GetLayerIdByName(IMapServer mapService, string name) { IMapServerInfo msInfo = mapService.GetServerInfo(mapService.DefaultMapName); IMapLayerInfos layerInfos = msInfo.MapLayerInfos; for (int i = 0; i < layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.Element[i]; if (layerInfo.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { return(layerInfo.ID); } } return(-1); }
/** * This method returns the Utility Network Layer information object. */ public IMapLayerInfo GetUNLayerInfo(IMapServer mapService) { IMapServerInfo mapServerInfo = mapService.GetServerInfo(mapService.DefaultMapName); IMapLayerInfos layerInfos = mapServerInfo.MapLayerInfos; for (int i = 0; i < layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.Element[i]; if (layerInfo.Type.Equals("Utility Network Layer", StringComparison.OrdinalIgnoreCase)) { return(layerInfo); } } return(null); }
private JSONArray getLayerInfo() { JSONArray layersArray = new JSONArray(); for (int i = 0; i < this.layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.get_Element(i); JSONObject jo = new JSONObject(); jo.AddString("name", layerInfo.Name); jo.AddLong("id", layerInfo.ID); jo.AddString("description", layerInfo.Description); layersArray.AddJSONObject(jo); } return(layersArray); }
private byte[] SampleOperationHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { var result = new OperationResult(); responseProperties = null; JsonObject jsonObj; bool found = operationInput.TryGetJsonObject(typeof(GpsData).Name, out jsonObj); if (!found) { throw new ArgumentNullException(typeof(GpsData).Name); } var gpsData = JsonableObject.FromJson <GpsData>(jsonObj.ToJson()); IMapLayerInfo layer = _serverObjectHelper.ServerObject.FindLayer(gpsData.LayerName); if (layer == null) { result.Success = false; return(Encoding.UTF8.GetBytes(result.ToJson())); } try { // TODO : add some ArcObjects code here to do whatever needed result.ExtraData = string.Format("Layer '{0}' has feature class '{1}'", layer.Name, _serverObjectHelper.ServerObject.GetFeatureClassFromLayer(layer).AliasName); result.Success = true; } catch (COMException comExc) { // Handle any errors that might occur. _logger.LogMessage(ServerLogger.msgType.error, "SampleOperationHandler", 666, comExc.Message); result.Success = false; } finally { // TODO : release any COM handles here, flush buffers etc. } return(Encoding.UTF8.GetBytes(result.ToJson())); }
public void Init(IServerObjectHelper pSOH) { IMapServer mapServer = pSOH.ServerObject as IMapServer; IMapServerDataAccess mapServerDataAccess = mapServer as IMapServerDataAccess; IMapServerInfo mapServerInfo = mapServer.GetServerInfo(mapServer.DefaultMapName); IMapLayerInfos layerInfos = mapServerInfo.MapLayerInfos; IMapLayerInfo ndLayerInfo = null; // Get the network dataset layer from current service for (var i = 0; i < layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.Element[i]; if (layerInfo.Type.Equals("Network Dataset Layer", StringComparison.InvariantCultureIgnoreCase)) { ndLayerInfo = layerInfo; break; } } // Get the network dataset if (ndLayerInfo != null) { var dt = mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, ndLayerInfo.ID); // Cast the dataset to required network dataset interface networkDataset = dt as INetworkDataset; } if (networkDataset != null) { // Open the streets feature class IDataset dataSet = networkDataset as IDataset; IFeatureWorkspace fWorkspace = dataSet.Workspace as IFeatureWorkspace; streetFC = fWorkspace.OpenFeatureClass(streetsName); // Get the Streets source ID INetworkSource streetNetworkSource = networkDataset.SourceByName[streetsName]; streetsSourceID = streetNetworkSource.ID; // Get the TraveTime attribute ID INetworkAttribute travelTimeAttribute = networkDataset.AttributeByName[costAttributeName]; travelTimeAttributeID = travelTimeAttribute.ID; } }
/// <summary> /// list layers in each dataframes in a TreeView /// </summary> private void listLayers(IMapServer pMapServer) { string strMapName = ""; IMapServerInfo pMSI = null; IMapLayerInfos pMLInfos = null; IMapLayerInfo pMLI = null; TreeViewItem pTVIDataFrame = null; for (int i = 0; i < pMapServer.MapCount; i++) { strMapName = pMapServer.get_MapName(i); if (!strMapName.Equals(pMapServer.DefaultMapName)) { continue; } //only for the active dataframe pMSI = pMapServer.GetServerInfo(strMapName); pMLInfos = pMSI.MapLayerInfos; pTVIDataFrame = CreateTreeViewItem(strMapName); tvwLayers.Items.Add(pTVIDataFrame); for (int j = 0; j < pMLInfos.Count; j++) { pMLI = pMLInfos.get_Element(j); AddTVItemForSubLayer(pTVIDataFrame, pMLInfos, pMLI, ref j); } pTVIDataFrame.IsExpanded = true; } if (pMapServer.MapCount > 1) { tvwLayers.Items.Add(""); TextBlock tb = new TextBlock() { Text = "<Other non-active dataframe cannot be used>", Foreground = new SolidColorBrush(Colors.DarkGray), FontStyle = FontStyles.Italic }; tvwLayers.Items.Add(tb); } }
/// <summary> /// Locates the feature class matching the supplied name. /// </summary> /// <param name="serverObject"></param> /// <param name="featureClassName"></param> /// <returns></returns> public static IFeatureClass FindFeatureClass(this ESRI.ArcGIS.Server.IServerObject serverObject, string featureClassName) { // Get the list of layers var mapServer = serverObject as IMapServer3; if (mapServer == null) { return(null); } var mapServerDataAccess = mapServer as IMapServerDataAccess; if (mapServerDataAccess == null) { return(null); } IMapLayerInfos mapLayerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos; for (int i = 0; i < mapLayerInfos.Count; i++) { IMapLayerInfo layer = mapLayerInfos.get_Element(i); if (layer == null || !layer.IsFeatureLayer) { continue; } var featureClass = mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, layer.ID) as IFeatureClass; if (featureClass == null || string.IsNullOrEmpty(featureClass.AliasName)) { continue; } if (featureClass.AliasName.EndsWith(featureClassName)) { return(featureClass); } } return(null); }
private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"application/json\"}"; String aoLayerType = ""; if (this.layerType.Equals("feature")) { aoLayerType = "Feature Layer"; } else if (this.layerType.Equals("raster")) { aoLayerType = "Raster Layer"; } else if (this.layerType.Equals("dataset")) { aoLayerType = "Network Dataset Layer"; } else { throw new Exception("Propety layerType has invalid value. Acceptable values are \"feature\", \"raster\", and \"dataset\"."); } JSONArray layersArray = new JSONArray(); for (int i = 0; i < this.layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.get_Element(i); String lType = layerInfo.Type; if (lType.Equals(aoLayerType)) { JSONObject jo = new JSONObject(); jo.AddString("name", layerInfo.Name); jo.AddLong("id", layerInfo.ID); jo.AddString("description", layerInfo.Description); layersArray.AddJSONObject(jo); } } JSONObject result = new JSONObject(); result.AddJSONArray("Layers", layersArray); return(Encoding.UTF8.GetBytes(result.ToJSONString(null))); }
private TreeViewItem CreateTreeViewItem(IMapLayerInfo pMLI) { System.Windows.Controls.CheckBox pCB = new System.Windows.Controls.CheckBox() { IsChecked = true, Margin = m_margin }; System.Windows.Controls.TextBlock pTB = new System.Windows.Controls.TextBlock() { Text = pMLI.Name, Margin = m_margin }; TextBlock ptbkInfo = new TextBlock() { Text = "(not featurelayer; can't export as JSON)", IsEnabled = false, Foreground = new SolidColorBrush(Colors.LightGray), FontStyle = FontStyles.Italic, Margin = m_margin }; StackPanel pSP = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal, Tag = pMLI.ID, VerticalAlignment = System.Windows.VerticalAlignment.Center }; pSP.Children.Add(pCB); pSP.Children.Add(pTB); if (!pMLI.IsFeatureLayer) { pCB.IsChecked = false; pSP.IsEnabled = false; pSP.Children.Add(ptbkInfo); } return(new TreeViewItem() { Header = pSP }); }
private void AddTVItemForSubLayer(TreeViewItem pTVIParent, IMapLayerInfos pMLInfos, IMapLayerInfo pMLI, ref int curMLIindex) { TreeViewItem pTVIlayer = CreateTreeViewItem(pMLI); //pMLI.Name, pMLI.ID, false); pTVIParent.Items.Add(pTVIlayer); ILongArray pSubLayersIDs = pMLI.SubLayers; if (pSubLayersIDs == null) { return; } //when it is a group layer IMapLayerInfo pChildMLI = null; for (int i = 0; i < pSubLayersIDs.Count; i++) { pChildMLI = pMLInfos.get_Element(++curMLIindex); AddTVItemForSubLayer(pTVIlayer, pMLInfos, pChildMLI, ref curMLIindex); } }
/// <summary> /// get RouteLayerInfo from Id /// </summary> /// <param name="routeLayerID">value of routeLayerID</param> /// <returns>object RouteLayerInfo</returns> private RouteLayerInfo GetRouteLayerInfo(int routeLayerID) { if (routeLayerID < 0) { throw new ArgumentOutOfRangeException("routeLayerID"); } IMapServer3 serverObject = this.GetMapServer(); IMapLayerInfos mapLayerInfos = serverObject.GetServerInfo(serverObject.DefaultMapName).MapLayerInfos; long count = mapLayerInfos.Count; for (int i = 0; i < count; i++) { IMapLayerInfo mapLayerInfo = mapLayerInfos.get_Element(i); if (mapLayerInfo.ID == routeLayerID) { return(new RouteLayerInfo(mapLayerInfo)); } } throw new ArgumentOutOfRangeException("routeLayerID"); }
private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"application/json\"}"; JSONArray layersArray = new JSONArray(); for (int i = 0; i < this.layerInfos.Count; i++) { IMapLayerInfo layerInfo = layerInfos.get_Element(i); JSONObject jo = new JSONObject(); jo.AddString("name", layerInfo.Name); jo.AddLong("id", layerInfo.ID); jo.AddString("type", layerInfo.Type); jo.AddString("description", layerInfo.Description); layersArray.AddJSONObject(jo); } JSONObject result = new JSONObject(); result.AddJSONArray("layers", layersArray); return(Encoding.UTF8.GetBytes(result.ToJSONString(null))); }
/// <summary> /// Retrieves a list of connection properties from the layers of a <see cref="IMapServer"/>. /// </summary> /// <param name="mapServer">A map server.</param> /// <param name="propertyNames">The names of the keys in each dictionary of the output object.</param> /// <returns> /// A list of <see cref="KeyValuePair<TKey,KValue>"/> objects. /// Each <see cref="KeyValuePair<TKey,KValue>.Key"/> corresponds to a data source name. /// Each value is a <see cref="Dictionary<TKey,TValue>"/> of connection properties. /// </returns> public static List <ConnectionProperties> GetConnectionProperties(this IMapServer mapServer /*, out List<string> propertyNames*/) { IMapLayerInfos mapLayerInfos = null; IMapLayerInfo mapLayerInfo = null; IMapServerDataAccess mapServerDA = null; IMapServerInfo mapServerInfo = null;; ////propertyNames = new List<string>(); IDataset dataset = null; IPropertySet connectionPropertySet = null; object namesObj, valuesObj; string[] names; object[] values; var output = new List <ConnectionProperties>(); try { mapServerDA = (IMapServerDataAccess)mapServer; // Get the server info for the default map. (This application will assume that there is only a single map: the default.) string mapName = mapServer.DefaultMapName; mapServerInfo = mapServer.GetServerInfo(mapName); // Loop through all of the layers in the map service... mapLayerInfos = mapServerInfo.MapLayerInfos; ConnectionProperties connectionProperties; for (int i = 0, l = mapLayerInfos.Count; i < l; i++) { mapLayerInfo = mapLayerInfos.get_Element(i); if (mapLayerInfo.IsComposite) { continue; } connectionProperties = new ConnectionProperties(mapLayerInfo.Name); try { dataset = mapServerDA.GetDataSource(mapName, i) as IDataset; } catch (NotImplementedException ex) { connectionProperties["error"] = ex.Message; output.Add(connectionProperties); continue; } if (dataset != null) { connectionPropertySet = dataset.Workspace.ConnectionProperties; connectionPropertySet.GetAllProperties(out namesObj, out valuesObj); names = namesObj as string[]; values = valuesObj as object[]; string name; for (int j = 0; j < names.Length; j++) { name = names[j]; connectionProperties[name] = values[j]; } output.Add(connectionProperties); } } } finally { foreach (var item in new object[] { mapLayerInfos, mapLayerInfo, mapServerDA, mapServerInfo, dataset, connectionPropertySet }) { if (item != null) { Marshal.ReleaseComObject(item); } } } return(output); }
/// <summary> /// Get the feature class that is associated with the supplied layer. /// </summary> /// <param name="serverObject"></param> /// <param name="layer"></param> /// <returns></returns> public static IFeatureClass GetFeatureClassFromLayer(this ESRI.ArcGIS.Server.IServerObject serverObject, IMapLayerInfo layer) { if (layer == null) { return(null); } // Get the list of layers var mapServer = serverObject as IMapServer3; if (mapServer == null) { return(null); } var mapServerDataAccess = mapServer as IMapServerDataAccess; if (mapServerDataAccess == null) { return(null); } return(mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, layer.ID) as IFeatureClass); }
private TreeViewItem CreateTreeViewItem(IMapLayerInfo pMLI) { System.Windows.Controls.CheckBox pCB = new System.Windows.Controls.CheckBox() { IsChecked = true, Margin = m_margin }; System.Windows.Controls.TextBlock pTB = new System.Windows.Controls.TextBlock() { Text = pMLI.Name, Margin = m_margin }; TextBlock ptbkInfo = new TextBlock() { Text = "(not featurelayer; can't export as JSON)", IsEnabled = false, Foreground = new SolidColorBrush(Colors.LightGray), FontStyle = FontStyles.Italic, Margin = m_margin }; StackPanel pSP = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal, Tag = pMLI.ID, VerticalAlignment = System.Windows.VerticalAlignment.Center }; pSP.Children.Add(pCB); pSP.Children.Add(pTB); if (!pMLI.IsFeatureLayer) { pCB.IsChecked = false; pSP.IsEnabled = false; pSP.Children.Add(ptbkInfo); } return new TreeViewItem() { Header = pSP }; }
/// <summary> /// Initializes a new instance of the <see cref="RouteLayerInfo"/> class /// </summary> /// <param name="mapLayerInfo">object IMapLayerInfo</param> public RouteLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.Id = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; }
public CustomLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.ID = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; }
/** * Performs edits to the geodatabase powering the map service that this SOE * extends * * @param feature * @param featureJSON * @throws Exception */ private byte[] addFeature(JsonObject featureJSON, out IFeature feature) { feature = null; IDataset fsDataset = (IDataset)this.fc; IWorkspace ws = fsDataset.Workspace; IWorkspaceEdit wsEdit = (IWorkspaceEdit)ws; try { // start an edit transaction to add a new feature to feature class wsEdit.StartEditing(false); wsEdit.StartEditOperation(); feature = fc.CreateFeature(); // set attributes if (this.editLayerInfo == null) { this.editLayerInfo = this.layerInfos.get_Element(this.layerId); if (!this.editLayerInfo.IsFeatureLayer) { return(createErrorObject( 403, "The layerId property of this SOE currently points to a layer (id: " + this.layerId + ") that is not a feature layer.", new String[] { "Only feature layers can be edited by this SOE.", "Modify SOE's layerId property using ArcGIS Manager or ArcGIS Desktop's Service Editor." })); } } IFields fields = this.editLayerInfo.Fields; JsonObject attributesJSON = null; featureJSON.TryGetJsonObject("attributes", out attributesJSON); System.Collections.IEnumerator itKeys = attributesJSON.GetEnumerator(); while (itKeys.MoveNext()) { KeyValuePair <string, object> kv = (KeyValuePair <string, object>)itKeys.Current; String key = kv.Key; int fieldId = fields.FindField(key); IField field = fields.get_Field(fieldId); object fieldValue = null; if (field.Editable) { //not using specific types based on field type, since can't assign value of any type to C# object attributesJSON.TryGetObject(key, out fieldValue); // set attribute field value feature.set_Value(fieldId, fieldValue); } } // retrieve geometry as json and convert it to ArcObject geometry JsonObject geometryJSON = null; featureJSON.TryGetJsonObject("geometry", out geometryJSON); IJSONConverterGeometry iConverter = new JSONConverterGeometryClass(); IJSONObject obj = new JSONObjectClass(); obj.ParseString(geometryJSON.ToJson()); IGeometry geometry = null; switch (this.fc.ShapeType) { case esriGeometryType.esriGeometryPoint: geometry = iConverter.ToPoint(obj); break; case esriGeometryType.esriGeometryMultipoint: geometry = iConverter.ToMultipoint(obj, false, false); break; case esriGeometryType.esriGeometryPolyline: geometry = iConverter.ToPolyline(obj, false, false); break; case esriGeometryType.esriGeometryPolygon: geometry = iConverter.ToPolygon(obj, false, false); break; } // set geometry feature.Shape = geometry; // store feature in feature class feature.Store(); // end edit transaction wsEdit.StopEditOperation(); wsEdit.StopEditing(true); } catch (Exception e) { if (wsEdit != null && wsEdit.IsBeingEdited()) { wsEdit.StopEditing(false); } feature = null; return(createErrorObject(500, "Error occured while editing layer " + this.layerId + ".", new String[] { "Error details:", e.Message })); } return(Encoding.UTF8.GetBytes(System.Boolean.TrueString)); }
private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; JsonObject infoJSON = new JsonObject(); infoJSON.AddString("name", ".Net Edit Features REST SOE"); infoJSON.AddString("description", "This SOE adds and edits features to a selected layer in a map service with editable data source registered to ArcGIS Server. Note that this SOE is not designed to work with hosted map services, or map service with read-only data source." + " The \"layers\" subresource returns all layers in the map service." + " The \"editFeature\" operation allows editing an existing feature in the layer indicated by this SOE's layerId property.\n" + " The \"addFeatures\" operation allows addition of a new feature to the layer indicated by this SOE's layerId property.\n" + " The acceptableSchema JSON below indicates the correct schema that could be used to add/edit features. This schema belongs to the layer " + "selected for editing by the ArcGIS Server administrator via the SOE's layerId property. This property's value can be " + "modified using ArcGIS Manager."); // validation - ensure user has provided right layer id property value. if (this.layerId > this.layerInfos.Count - 1) { return(createErrorObject(406, "Layer Id " + this.layerId + " is invalid.", new String[] { "Acceptable layer ids are between 0 and " + (layerInfos.Count - 1) + ".", "Also ensure that the id points to a feature layer." })); } // inform the user that edits can be done only on feature layers, if no // feature layer corresponds to user-provided layerId if (this.editLayerInfo == null) { this.editLayerInfo = this.layerInfos.get_Element(this.layerId); if (!this.editLayerInfo.IsFeatureLayer) { return(createErrorObject( 403, "The layerId property of this SOE currently points to a layer (id: " + this.layerId + ") that is not a feature layer.", new String[] { "Only feature layers can be edited by this SOE.", "Modify SOE's layerId property using ArcGIS Manager or ArcGIS Desktop's Service Editor." })); } } // Grab the fc powering the layer if its null, which means it did not get initialized in construct(), thereby // suggesting that the layerId property value is incorrect. if (this.fc == null) { // The down side of grabbing fc here is // that a new instance of fc is created once for every request. // Can't create fc in init(), since layerId property value for a // particular service is not necessarily available always when init() is invoked. this.fc = (IFeatureClass)this.mapServerDataAccess.GetDataSource(this.mapServerInfo.Name, this.layerId); if (this.fc == null) { // if its still null, return error return(createErrorObject( 406, "Incorrect layer id provided.", new String[] { "Please provide layer id of a feature layer." })); } } infoJSON.AddString("Layer selected for editing", editLayerInfo.Name.ToString() + " (" + layerId + ")"); JsonObject schemaJSON = getSchemaJSON(); infoJSON.AddObject("acceptableSchema", schemaJSON); return(Encoding.UTF8.GetBytes(infoJSON.ToJson())); }
public CustomLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.ID = mapLayerInfo.ID; this.Extent = mapLayerInfo.Extent; }
private void btnExportAsJSON_Click(object sender, RoutedEventArgs e) { string dataframeName; string outFile; IMapLayerInfos pMLInfos = null; IMapLayerInfo pMLI = null; //checking the existence of the output folder //DirectoryInfo outDirInfo = new DirectoryInfo(txtOutputFolder.Text); string outDir = txtOutputFolder.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(txtMXD.Text); if (Directory.Exists(outDir)) { MessageBoxResult msgRes = System.Windows.MessageBox.Show(String.Format("Folder already exists \n{0}. \nDo you want to over write it?", outDir), "Output Folder", MessageBoxButton.YesNo, MessageBoxImage.Question); if (msgRes == MessageBoxResult.No) { System.Windows.MessageBox.Show("Operation is cancelled", "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } else { try { Directory.Delete(outDir, true); } catch (Exception ex) { System.Windows.MessageBox.Show(String.Format("Failed to delete the folder \n{0}\n\n{1}", outDir, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error); return; } } } Directory.CreateDirectory(outDir); prsProgress.IsIndeterminate = false; prsProgress.Visibility = System.Windows.Visibility.Visible; TreeViewItem pTVIDataframe = null; for (int i = 0; i < m_pMapServer.MapCount; i++) { dataframeName = m_pMapServer.get_MapName(i); if (dataframeName != m_pMapServer.DefaultMapName) { continue; } //ONLY for the default dataframe pTVIDataframe = tvwLayers.Items[0] as TreeViewItem; //getting REST resources including layer infos string restOutputResource = Utils.GetLayersResource(m_pMapServer); JSONObject jObject = new JSONObject(); jObject.ParseString(restOutputResource); IJSONArray layers = null; jObject.TryGetValueAsArray("layers", out layers); pMLInfos = m_pMapServer.GetServerInfo(dataframeName).MapLayerInfos; prsProgress.Maximum = pMLInfos.Count; for (int j = 0; j < pMLInfos.Count; j++) { pMLI = pMLInfos.get_Element(j); if (pMLI.IsFeatureLayer) { bool isSelected = false; IsLayerSelectedForExport(pTVIDataframe, pMLI.ID, ref isSelected); if (isSelected) { IJSONObject layer = (IJSONObject)layers.get_Value(j); String renderer = Utils.GetRendererFromLayer(layer.ToJSONString(null)); outFile = string.Format(@"{0}\{1:000} {2}.json", outDir, pMLI.ID, Utils.ValidateFileName(pMLI.Name)); try { File.WriteAllText(outFile, renderer); } catch (Exception ex) { System.Windows.MessageBox.Show(String.Format("Failed to write content to the file\n{0}\n\n{1}", outFile, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error); prsProgress.Visibility = System.Windows.Visibility.Hidden; return; } } } prsProgress.Value += 1; } } prsProgress.Visibility = System.Windows.Visibility.Hidden; System.Windows.MessageBox.Show(String.Format("Conversion Completed\nOutput Path: {0}", outDir), "JSON Conversion", MessageBoxButton.OK, MessageBoxImage.Information); }
public ExportLayerInfo(IMapLayerInfo mapLayerInfo) { this.Name = mapLayerInfo.Name; this.ID = mapLayerInfo.ID; }
/** * Performs edits to the geodatabase powering the map service that this SOE * extends * * @param feature * @param featureJSON * @throws Exception */ private byte[] addFeature(JsonObject featureJSON, out IFeature feature) { feature = null; IDataset fsDataset = (IDataset)this.fc; IWorkspace ws = fsDataset.Workspace; IWorkspaceEdit wsEdit = (IWorkspaceEdit)ws; try { // start an edit transaction to add a new feature to feature class wsEdit.StartEditing(false); wsEdit.StartEditOperation(); feature = fc.CreateFeature(); // set attributes if (this.editLayerInfo == null) { this.editLayerInfo = this.layerInfos.get_Element(this.layerId); if (!this.editLayerInfo.IsFeatureLayer) { return createErrorObject( 403, "The layerId property of this SOE currently points to a layer (id: " + this.layerId + ") that is not a feature layer.", new String[] { "Only feature layers can be edited by this SOE.", "Modify SOE's layerId property using ArcGIS Manager or ArcGIS Desktop's Service Editor." }); } } IFields fields = this.editLayerInfo.Fields; JsonObject attributesJSON = null; featureJSON.TryGetJsonObject("attributes", out attributesJSON); System.Collections.IEnumerator itKeys = attributesJSON.GetEnumerator(); while (itKeys.MoveNext()) { KeyValuePair<string, object> kv = (KeyValuePair<string, object>)itKeys.Current; String key = kv.Key; int fieldId = fields.FindField(key); IField field = fields.get_Field(fieldId); object fieldValue = null; if (field.Editable) { //not using specific types based on field type, since can't assign value of any type to C# object attributesJSON.TryGetObject(key, out fieldValue); // set attribute field value feature.set_Value(fieldId, fieldValue); } } // retrieve geometry as json and convert it to ArcObject geometry JsonObject geometryJSON = null; featureJSON.TryGetJsonObject("geometry", out geometryJSON); IJSONConverterGeometry iConverter = new JSONConverterGeometryClass(); IJSONObject obj = new JSONObjectClass(); obj.ParseString(geometryJSON.ToJson()); IGeometry geometry = null; switch (this.fc.ShapeType) { case esriGeometryType.esriGeometryPoint: geometry = iConverter.ToPoint(obj); break; case esriGeometryType.esriGeometryMultipoint: geometry = iConverter.ToMultipoint(obj, false, false); break; case esriGeometryType.esriGeometryPolyline: geometry = iConverter.ToPolyline(obj, false, false); break; case esriGeometryType.esriGeometryPolygon: geometry = iConverter.ToPolygon(obj, false, false); break; } // set geometry feature.Shape = geometry; // store feature in feature class feature.Store(); // end edit transaction wsEdit.StopEditOperation(); wsEdit.StopEditing(true); } catch (Exception e) { if (wsEdit != null && wsEdit.IsBeingEdited()) { wsEdit.StopEditing(false); } return createErrorObject(500, "Error occured while editing layer " + this.layerId + ".", new String[] { "Error details:", e.Message }); } return Encoding.UTF8.GetBytes(System.Boolean.TrueString); }
private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; JsonObject infoJSON = new JsonObject(); infoJSON.AddString("name", ".Net Edit Features REST SOE"); infoJSON.AddString("description", "This SOE adds and edits features to a selected layer in the host map service. " + "Note that this SOE is not designed to work with map services that have features stored in SDC data format." + " The \"layers\" subresource returns all layers in the map service." + " The \"editFeature\" operation allows editing an existing feature in the layer indicated by this SOE's layerId property.\n" + " The \"addFeatures\" operation allows addition of a new feature to the layer indicated by this SOE's layerId property.\n" + " The acceptableSchema JSON below indicates the correct schema that could be used to add/edit features. This schema belongs to the layer " + "selected for editing by the ArcGIS Server administrator via the SOE's layerId property. This property's value can be " + "modified using ArcGIS Manager."); // validation - ensure user has provided right layer id property value. if (this.layerId > this.layerInfos.Count - 1) { return createErrorObject(406, "Layer Id " + this.layerId + " is invalid.", new String[] { "Acceptable layer ids are between 0 and " + (layerInfos.Count - 1) + ".", "Also ensure that the id points to a feature layer." }); } // inform the user that edits can be done only on feature layers, if no // feature layer corresponds to user-provided layerId if (this.editLayerInfo == null) { this.editLayerInfo = this.layerInfos.get_Element(this.layerId); if (!this.editLayerInfo.IsFeatureLayer) { return createErrorObject( 403, "The layerId property of this SOE currently points to a layer (id: " + this.layerId + ") that is not a feature layer.", new String[] { "Only feature layers can be edited by this SOE.", "Modify SOE's layerId property using ArcGIS Manager or ArcGIS Desktop's Service Editor." }); } } // Grab the fc powering the layer if its null, which means it did not get initialized in construct(), thereby // suggesting that the layerId property value is incorrect. if (this.fc == null) { // The down side of grabbing fc here is // that a new instance of fc is created once for every request. // Can't create fc in init(), since layerId property value for a // particular service is not necessarily available always when init() is invoked. this.fc = (IFeatureClass) this.mapServerDataAccess.GetDataSource(this.mapServerInfo.Name, this.layerId); if (this.fc == null) { // if its still null, return error return createErrorObject( 406, "Incorrect layer id provided.", new String[] { "Please provide layer id of a feature layer." }); } } infoJSON.AddString("Layer selected for editing", editLayerInfo.Name.ToString() + " (" + layerId + ")"); JsonObject schemaJSON = getSchemaJSON(); infoJSON.AddObject("acceptableSchema", schemaJSON); return Encoding.UTF8.GetBytes(infoJSON.ToJson()); }
public void Construct(IPropertySet props) { configProps = props; string lid = (string)props.GetProperty("layerId"); this.layerId = Convert.ToInt32(lid); this.fc = (IFeatureClass) this.mapServerDataAccess.GetDataSource(this.mapServerInfo.Name, this.layerId); this.editLayerInfo = this.layerInfos.get_Element(this.layerId); }
private void AddTVItemForSubLayer(TreeViewItem pTVIParent, IMapLayerInfos pMLInfos, IMapLayerInfo pMLI, ref int curMLIindex) { TreeViewItem pTVIlayer = CreateTreeViewItem(pMLI); //pMLI.Name, pMLI.ID, false); pTVIParent.Items.Add(pTVIlayer); ILongArray pSubLayersIDs = pMLI.SubLayers; if (pSubLayersIDs == null) return; //when it is a group layer IMapLayerInfo pChildMLI = null; for (int i = 0; i < pSubLayersIDs.Count; i++) { pChildMLI = pMLInfos.get_Element(++curMLIindex); AddTVItemForSubLayer(pTVIlayer, pMLInfos, pChildMLI, ref curMLIindex); } }
protected IMapLayerInfo[] GetMapLayerInfo() { IMapServer3 mapServer = m_serverObjectHelper.ServerObject as IMapServer3; if (mapServer == null) { throw new Exception("Unable to access the map server."); } IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos; IMapLayerInfo[] result = new IMapLayerInfo[layerInfos.Count]; for (int i = 0; i < result.Length; i++) { result[i] = layerInfos.get_Element(i); } return result; }
/// <summary> /// Initializes a new instance of the SurfaceLayerInfo class from layer information /// </summary> /// <param name="mapLayerInfo">The layer information</param> /// <param name="rasterFromLayer">The raster from the layer</param> public SurfaceLayerInfo(IMapLayerInfo mapLayerInfo, IRaster rasterFromLayer) { this.MapLayerInfo = mapLayerInfo; this.AnalysisSurface = new AnalysisSurface(rasterFromLayer); }