public JsonObject ToJsonObject() { JsonObject result = new JsonObject(); if (Attributes.Count > 0) { JsonObject attributes = new JsonObject(); foreach (KeyValuePair<string, object> kvp in Attributes) { attributes.AddObject(kvp.Key, kvp.Value); } result.AddJsonObject("attributes", attributes); } if (Geometry != null) { result.AddJsonObject("geometry", Conversion.ToJsonObject(Geometry)); } return result; }
private byte[] PrintOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; JsonObject info; bool found = operationInput.TryGetJsonObject("printParameters", out info); if (!found || info == null) { throw new ArgumentNullException("printParameters"); } ExportMapInfo printInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <ExportMapInfo>(info.ToJson()); JsonObject result = new JsonObject(); ExportMap export = new ExportMap(); string outmsg = string.Empty; bool isPrinted = export.Export(printInfo, out outmsg); PrintResult pr = new PrintResult(); if (isPrinted) { pr.IsPrinted = isPrinted; pr.FileName = outmsg; pr.OutMsg = "制图成功!"; } else { pr.IsPrinted = isPrinted; pr.FileName = "未找到!"; pr.OutMsg = outmsg; } result.AddObject("result", pr); return(Encoding.UTF8.GetBytes(result.ToJson())); }
private byte[] ListFilesHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; FileInfo[] Files = new DirectoryInfo(localFilePath).GetFiles("*.txt"); JsonObject[] filesArr = new JsonObject[Files.Length]; for (int i = 0; i < Files.Length; i++) { JsonObject fileJson = new JsonObject(); fileJson.AddString("filename", Files[i].Name); filesArr[i] = fileJson; } JsonObject filesJson = new JsonObject(); filesJson.AddObject("files", filesArr); return(Encoding.UTF8.GetBytes(filesJson.ToJson())); }
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()); }
private byte[] MakeDomainOptionsHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; string strSDELayerName; bool found = operationInput.TryGetString("SDEName", out strSDELayerName); if (!found || string.IsNullOrEmpty(strSDELayerName)) { throw new ArgumentNullException("SDEName"); } string strFieldName; found = operationInput.TryGetString("fieldname", out strFieldName); if (!found || string.IsNullOrEmpty(strSDELayerName)) { throw new ArgumentNullException("fieldname"); } IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName); IField pField; Dictionary <string, string> dicDomainValues; option opt = new option(); opt.Result = "OK"; List <Dictionary <string, string> > lstDics = new List <Dictionary <string, string> >(); int iFieldIndex = pStandAloneTable.Table.Fields.FindField(strFieldName); if (iFieldIndex != -1) { pField = pStandAloneTable.Table.Fields.get_Field(iFieldIndex); IDomain pDomain; pDomain = pField.Domain; if (pDomain != null) { ICodedValueDomain pCodedValueDomain; pCodedValueDomain = pDomain as ICodedValueDomain; if (pCodedValueDomain != null) { for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++) { dicDomainValues = new Dictionary <string, string>(); string name = pCodedValueDomain.get_Value(k).ToString(); string value = pCodedValueDomain.get_Name(k).ToString(); dicDomainValues.Add("DisplayText", value); dicDomainValues.Add("Value", name); lstDics.Add(dicDomainValues); } } } } else { opt.Result = "Field not found"; } JsonObject result = new JsonObject(); result.AddString("Result", opt.Result); result.AddObject("Options", lstDics); return(Encoding.UTF8.GetBytes(result.ToJson())); }
private byte[] ReportDomainsHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; string strSDELayerName; bool found = operationInput.TryGetString("SDEName", out strSDELayerName); if (!found || string.IsNullOrEmpty(strSDELayerName)) { throw new ArgumentNullException("SDEName"); } IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName); IField pField; Dictionary <string, Dictionary <string, string> > dicResults = new Dictionary <string, Dictionary <string, string> >(); Dictionary <string, string> dicDomainValues; for (int i = 0; i <= pStandAloneTable.Table.Fields.FieldCount - 1; i++) { pField = pStandAloneTable.Table.Fields.get_Field(i); IDomain pDomain; pDomain = pField.Domain; if (pDomain != null) { //PrintDomainValues(pField.Name, pDomain.DomainID); dicDomainValues = new Dictionary <string, string>(); ICodedValueDomain pCodedValueDomain; pCodedValueDomain = pDomain as ICodedValueDomain; if (pCodedValueDomain != null) { //Console.WriteLine(pField.Name + ": " + pDomain.DomainID.ToString()); //Console.WriteLine("------------------------------------------"); for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++) { string name = pCodedValueDomain.get_Value(k).ToString(); string value = pCodedValueDomain.get_Name(k).ToString(); dicDomainValues.Add(name, value); //Console.WriteLine(name + ", " + value); } //Console.WriteLine("------------------------------------------"); //Console.WriteLine(Environment.NewLine); dicResults.Add(pField.Name, dicDomainValues); } } } JsonObject result = new JsonObject(); result.AddObject("Domains", dicResults); //result.AddString("SDEName", strSDELayerName); return(Encoding.UTF8.GetBytes(result.ToJson())); }
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())); }
private byte[] DescribeLayersHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; JsonObject tResult = new JsonObject(); tResult.AddLong("AvailableLayerCount", m_ExtractableParams.Count); JsonObject tLayersJson = new JsonObject(); foreach (ExtractionLayerConfig layer in m_ExtractableParams){ //int id = layer.LayerID; string lyrName = layer.LayerName; string requestParameter = layer.ParamName; string extractionType = layer.ExtractionType.ToString(); JsonObject tLayerJson = new JsonObject(); //tLayerJson.AddLong("LayerId", id); tLayerJson.AddString("LayerName",lyrName); tLayerJson.AddString("LayerDescription", layer.LayerDescription); tLayerJson.AddString("ExtractionType", extractionType); if (layer.HasCategories) { IFeatureClass tLayerAsFc = (IFeatureClass)layer.LayerDataset; string tCatName = tLayerAsFc.Fields.get_Field(layer.CategoryField).Name; tLayerJson.AddString("CategoryField", tCatName); } tLayersJson.AddObject(requestParameter,tLayerJson); } tResult.AddObject("Extractions", tLayersJson); byte[] tOutput = System.Text.Encoding.UTF8.GetBytes(tResult.ToJson()); return tOutput; }
private byte[] GetSpeciesExtentHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"text/javascript\"}"; long? idnoValue; //out parameter for the ID_NO as a long operationInput.TryGetAsLong("ID_NO", out idnoValue); //get the ID_NO parameter IQueryFilter queryFilter = new QueryFilterClass(); //instantiate a filter for the passed species queryFilter.WhereClause = "ID_NO='" + idnoValue + "' AND Legend<>''"; //set the where clause IFeatureCursor featureCursor = speciesFeatureClass.Search(queryFilter, false); //get the feature cursor to the matching features IFeature feature = null; //for iterating through the features IGeometryCollection pGeometryCollection = new GeometryBagClass() as IGeometryCollection; //instantiate a geometry bag to get the extent object obj = Type.Missing; //needed to add geometries to the geometry bag while ((feature = featureCursor.NextFeature()) != null) //iterate through the matching features and add the geometries to the geometry bag { pGeometryCollection.AddGeometry(feature.ShapeCopy, ref obj, ref obj); //add the geometry } JsonObject result = new JsonObject(); //create the return json object IEnvelope extent = (pGeometryCollection as IGeometry).Envelope; //get the extent of the geometry bag JsonObject jsonExtent = Conversion.ToJsonObject(extent); //convert the extent to json //TODO: Set the spatial reference for the extent in the SOE - at the moment it is set in the client code result.AddObject("extent", jsonExtent); //write the extent to the result object result.AddString("featureCount", pGeometryCollection.GeometryCount.ToString()); //get the number of features return Encoding.UTF8.GetBytes(result.ToJson()); //return the json }
private byte[] ReportDomainsHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; string strSDELayerName; bool found = operationInput.TryGetString("SDEName", out strSDELayerName); if (!found || string.IsNullOrEmpty(strSDELayerName)) throw new ArgumentNullException("SDEName"); IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName); IField pField; Dictionary<string, Dictionary<string, string>> dicResults = new Dictionary<string, Dictionary<string, string>>(); Dictionary<string, string> dicDomainValues; for (int i = 0; i <= pStandAloneTable.Table.Fields.FieldCount - 1; i++) { pField = pStandAloneTable.Table.Fields.get_Field(i); IDomain pDomain; pDomain = pField.Domain; if (pDomain != null) { //PrintDomainValues(pField.Name, pDomain.DomainID); dicDomainValues = new Dictionary<string, string>(); ICodedValueDomain pCodedValueDomain; pCodedValueDomain = pDomain as ICodedValueDomain; if (pCodedValueDomain != null) { //Console.WriteLine(pField.Name + ": " + pDomain.DomainID.ToString()); //Console.WriteLine("------------------------------------------"); for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++) { string name = pCodedValueDomain.get_Value(k).ToString(); string value = pCodedValueDomain.get_Name(k).ToString(); dicDomainValues.Add(name, value); //Console.WriteLine(name + ", " + value); } //Console.WriteLine("------------------------------------------"); //Console.WriteLine(Environment.NewLine); dicResults.Add(pField.Name, dicDomainValues); } } } JsonObject result = new JsonObject(); result.AddObject("Domains", dicResults); //result.AddString("SDEName", strSDELayerName); return Encoding.UTF8.GetBytes(result.ToJson()); }
private byte[] MakeDomainOptionsHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; string strSDELayerName; bool found = operationInput.TryGetString("SDEName", out strSDELayerName); if (!found || string.IsNullOrEmpty(strSDELayerName)) throw new ArgumentNullException("SDEName"); string strFieldName; found = operationInput.TryGetString("fieldname", out strFieldName); if (!found || string.IsNullOrEmpty(strSDELayerName)) throw new ArgumentNullException("fieldname"); IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName); IField pField; Dictionary<string, string> dicDomainValues; option opt = new option(); opt.Result = "OK"; List<Dictionary<string, string>> lstDics = new List<Dictionary<string, string>>(); int iFieldIndex = pStandAloneTable.Table.Fields.FindField(strFieldName); if (iFieldIndex != -1) { pField = pStandAloneTable.Table.Fields.get_Field(iFieldIndex); IDomain pDomain; pDomain = pField.Domain; if (pDomain != null) { ICodedValueDomain pCodedValueDomain; pCodedValueDomain = pDomain as ICodedValueDomain; if (pCodedValueDomain != null) { for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++) { dicDomainValues = new Dictionary<string, string>(); string name = pCodedValueDomain.get_Value(k).ToString(); string value = pCodedValueDomain.get_Name(k).ToString(); dicDomainValues.Add("DisplayText", value); dicDomainValues.Add("Value", name); lstDics.Add(dicDomainValues); } } } } else { opt.Result = "Field not found"; } JsonObject result = new JsonObject(); result.AddString("Result", opt.Result); result.AddObject("Options", lstDics); return Encoding.UTF8.GetBytes(result.ToJson()); }