当前位置: 首页>>代码示例>>C#>>正文


C# JsonObject.TryGetJsonObject方法代码示例

本文整理汇总了C#中JsonObject.TryGetJsonObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.TryGetJsonObject方法的具体用法?C# JsonObject.TryGetJsonObject怎么用?C# JsonObject.TryGetJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonObject的用法示例。


在下文中一共展示了JsonObject.TryGetJsonObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addFeature

        /**
         * 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);
//.........这里部分代码省略.........
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:101,代码来源:NetEditFeaturesRESTSOE.cs

示例2: isSchemaValid

        // Validates schema of JSON provided by user for editing
        private bool isSchemaValid(JsonObject userFeatureJson)
        {
            Fields fields = (Fields) editLayerInfo.Fields;
            string[] fieldsSet = new string[fields.FieldCount];
            for (int i = 0; i < fields.FieldCount; i++)
            {
                fieldsSet[i] = fields.get_Field(i).Name;
            }

            JsonObject attributesJson;
            userFeatureJson.TryGetJsonObject("attributes", out attributesJson);

            System.Collections.IEnumerator itKeys = attributesJson.GetEnumerator();

            while (itKeys.MoveNext())
            {
                String key = (String) itKeys.Current;
                IField field = fields.get_Field(fields.FindField(key));

                // as long as user supplied schema contains all editable fields and
        	    // is a subset of feature class schema, we are ok.
                if (field.Editable && !fieldsSet.Contains(key))
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:30,代码来源:NetEditFeaturesRESTSOE.cs

示例3: ExtractByPolygonHandler

 private byte[] ExtractByPolygonHandler(NameValueCollection boundVariables,
     JsonObject operationInput,
     string outputFormat,
     string requestProperties,
     out string responseProperties)
 {
     string search_id;
     bool found = operationInput.TryGetString("search_id", out search_id);
     if (!found || string.IsNullOrEmpty(search_id))
     {
         throw new ArgumentNullException("search_id");
     }
     // input polygon - REQUIRED - the polygon to summarise data within
     JsonObject jsonPolygon;
     found = operationInput.TryGetJsonObject("polygon", out jsonPolygon);
     if (!found)
     {
         throw new ArgumentNullException("polygon");
     }
     IPolygon extractionPolygon = Conversion.ToGeometry(jsonPolygon, esriGeometryType.esriGeometryPolygon) as IPolygon;
     long? jsonWkid;
     found = operationInput.TryGetAsLong("input_wkid", out jsonWkid);
     if (!found)
     {
         throw new ArgumentNullException("input_wkid", "WKID numeric value for spatial reference of input point must be provided");
     }
     if (jsonWkid.HasValue)
     {
         int wkid = (int)jsonWkid.Value;
         ISpatialReferenceFactory2 tInSRFac = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
         ISpatialReference tInSR = tInSRFac.CreateSpatialReference(wkid);
         extractionPolygon.SpatialReference = tInSR;
     }
     else
     {
         // we won't get here
         extractionPolygon.SpatialReference = new UnknownCoordinateSystemClass();
     }
     bool? reqReturnAsAttributes;
     bool returnAsAttributes = false;
     found = operationInput.TryGetAsBoolean("extractToPolygonAttributes", out reqReturnAsAttributes);
     if (found && reqReturnAsAttributes.HasValue)
     {
         returnAsAttributes = (bool)reqReturnAsAttributes;
     }
     List<ExtractionLayerConfig> extractionRequests = new List<ExtractionLayerConfig>();
     foreach (ExtractionLayerConfig tExtLayerInfo in m_ExtractableParams)
     {
         string jsonParam = tExtLayerInfo.ParamName;
         bool? wasRequested;
         found = operationInput.TryGetAsBoolean(jsonParam, out wasRequested);
         if (found && wasRequested.HasValue && (bool)wasRequested)
         {
             extractionRequests.Add(tExtLayerInfo);
         }
     }
     logger.LogMessage(ServerLogger.msgType.debug, "ExtractByPolygonHandler", 99,
                   "Processed inputs, attempting " + extractionRequests.Count.ToString() + " extractions");
     // now need to convert the IPolygon to a geodataset, (a polygon one) for feature
     // extractions.
     IWorkspace inMemWksp = CreateInMemoryWorkspace() as IWorkspace;
     IFeatureWorkspace inMemFeatWksp = inMemWksp as IFeatureWorkspace;
     IFeatureClass tPolyAsFC = CreateFeatureClassFromGeometry(extractionPolygon, inMemFeatWksp, extractionPolygon.SpatialReference.FactoryCode);
     IArea tArea = extractionPolygon as IArea;
     if (AddAField(tPolyAsFC,"Total_Area",esriFieldType.esriFieldTypeDouble))
     {
         IFeatureCursor tFCursor = tPolyAsFC.Search(null,false);
         IFeature tPolyAsFeature = tFCursor.NextFeature();
         tPolyAsFeature.set_Value(tPolyAsFC.FindField("Total_Area"),tArea.Area);
         tPolyAsFeature.Store();
     }
     IGeoDataset tPolygonGDS = tPolyAsFC as IGeoDataset;
     // now do the extractions from it
     ExtractionResultCollection tExtractionResults =
         ProcessExtractions(search_id,tPolygonGDS, null, extractionRequests);
     // Warning! Don't go assuming that the suggestively-named responseProperties can be set to anything
     // helpful to describe, say, response properties. Try setting it to anything other than null
     // (that I have tried) and you get "500 Unexpected Error" message and lose the best part of an
     // afternoon working out why!
     //responseProperties = "Extractions processed successfully";
     responseProperties = null;
     logger.LogMessage(ServerLogger.msgType.debug, "ExtractByPolygonHandler", 99,
                   "Extractions complete, returning feature");
     if (returnAsAttributes)
     {
         IRecordSetInit returnRecSet = new RecordSetClass();
         IGeoDataset tFinalGDS = tExtractionResults.ResultsAsAttributedGeodataset;
         returnRecSet.SetSourceTable(tFinalGDS as ITable, null);
         IRecordSet recset = returnRecSet as IRecordSet;
         byte[] jsonFeature = Conversion.ToJson(recset);
         return jsonFeature;
     }
     else
     {
         JsonObject tResultsAsJson = tExtractionResults.ResultsAsJson;
         byte[] jsonFeatures = System.Text.Encoding.UTF8.GetBytes(tResultsAsJson.ToJson());
         return jsonFeatures;
     }
 }
开发者ID:harry-gibson,项目名称:watershed-soe,代码行数:99,代码来源:WatershedSOE.cs

示例4: addNewFeatureOperHandler

        private byte[] addNewFeatureOperHandler(NameValueCollection boundVariables,
                                                  JsonObject operationInput,
                                                      string outputFormat,
                                                      string requestProperties,
                                                  out string responseProperties)
        {

            responseProperties = null;

            // get the feature JSON
            JsonObject newFeatureJSON = null;
            operationInput.TryGetJsonObject("featureJSON", out newFeatureJSON);

            // add the new feature
            IFeature newFeature;
            var bytes = addFeature(newFeatureJSON, out newFeature);

            if (null == newFeature)
                return bytes; //return error
            
            // send response back to client app
            var response = new JsonObject();
            response.AddString("status", "success");
            response.AddString("message", "Feature " + newFeature.OID + " added.");

            return Encoding.UTF8.GetBytes(response.ToJson());
        }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:27,代码来源:NetEditFeaturesRESTSOE.cs

示例5: ExportLayerHandler

        private byte[] ExportLayerHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat,
            string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            try
            {

                //hydrate the input
                JsonObject feedPropertiesObject = null;
                JsonObject jsonLocation;
                IGeometry location = null;
                IExportProperties exportProperties = null;
                string whereClause;
                string geometryType;
                GPX.Server.Extension.Spatial.MapServer mapserver = new Spatial.MapServer(serverObjectHelper.ServerObject);

                logger.LogMessage(ServerLogger.msgType.infoDetailed, "ExportLayerHandler", 999999, "Beginning Export");

                //layerID
                int layerID = Convert.ToInt32(boundVariables["ExportLayersId"]);

                if (!operationInput.TryGetJsonObject("exportProperties", out feedPropertiesObject))
                    throw new ArgumentException("Error: Could not parse exportProperties" + feedPropertiesObject.ToJson());

                //initialise the correct export properties
                if (feedPropertiesObject != null)
                {
                    if (outputFormat == GEORSS_FORMAT)
                    {

                        exportProperties = new GeoRSSExportProperties(feedPropertiesObject.ToJson());

                    }
                    else
                    {
                        exportProperties = new GeoJsonExportProperties(feedPropertiesObject.ToJson());
                    }
                }

                if (!operationInput.TryGetJsonObject("filterGeometry", out jsonLocation))
                    throw new ArgumentNullException("filterGeometry");

                if (jsonLocation != null)
                {
                    if (!operationInput.TryGetString("geometryType", out geometryType))
                        throw new ArgumentNullException("Can supply a geometry without a geometryType");

                    switch (geometryType)
                    {
                        case "Polygon":
                            location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPolygon);
                            if (location == null)
                                throw new ArgumentException("ExportLayerHandler: invalid polygon", "filterGeometry");
                            break;
                        case "Point":
                            location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint);
                            if (location == null)
                                throw new ArgumentException("ExportLayerHandler: invalid point", "filterGeometry");
                            break;
                        case "Line":
                            location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPolyline);
                            if (location == null)
                                throw new ArgumentException("ExportLayerHandler: invalid polyline", "filterGeometry");
                            break;
                        default:
                            break;
                    }

                }

                if (!operationInput.TryGetString("where", out whereClause))
                    throw new ArgumentNullException("where");

                //run the query on the map server
                RecordSet results = mapserver.Query(layerID, location, whereClause, exportProperties.GeometryField, exportProperties.OutputSpatialReference);

                //generate the export
                string finalExport = string.Empty;
                string xmlString = string.Empty;

                if (outputFormat == GEORSS_FORMAT)
                {
                    if (exportProperties != null)
                    {

                        var feedProperties = (GeoRSSExportProperties)exportProperties;
                        GeoRSSExport export = new GeoRSSExport();
                        export.CreateExport(results, exportProperties);

                        StringBuilder sb = new StringBuilder();
                        XmlWriter xmlWriter = XmlWriter.Create(sb);

                        if (feedProperties.FeedFormat == "Atom")
                        {
                            export.SaveAsAtom10(xmlWriter);
                            responseProperties = "{\"Content-Type\" : \"application/atom+xml\"}";
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:geoplex,项目名称:arcgis-exporter-extension,代码行数:101,代码来源:Exporter.cs

示例6: CreateWatershedHandler

        private byte[] CreateWatershedHandler(NameValueCollection boundVariables,
            JsonObject operationInput,
            string outputFormat,
            string requestProperties,
            out string responseProperties)
        {
            responseProperties = null;

            #region Process the REST arguments
            // hydroshed_id - REQUIRED - to identify the overall result
            string search_id;
            bool found = operationInput.TryGetString("search_id", out search_id);
            if (!found || string.IsNullOrEmpty(search_id))
            {
                throw new ArgumentNullException("search_id");
            }
            // input point - REQUIRED - the search location
            JsonObject jsonPoint;
            found = operationInput.TryGetJsonObject("location", out jsonPoint);
            if (!found)
            {
                throw new ArgumentNullException("location");
            }
            IPoint locationpoint = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
            long? jsonWkid;
            found = operationInput.TryGetAsLong("input_wkid", out jsonWkid);
            if (!found)
            {
                throw new ArgumentNullException("input_wkid", "WKID numeric value for spatial reference of input point must be provided");
            }
            if (jsonWkid.HasValue)
            {
                int wkid = (int)jsonWkid.Value;
                ISpatialReferenceFactory2 tInSRFac = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
                ISpatialReference tInSR = tInSRFac.CreateSpatialReference(wkid);
                locationpoint.SpatialReference = tInSR;
            }
            // extent - OPTIONAL - we will use full extent if not provided but this is slow!!
            // TODO maybe preferable to have the extent looked up in the SOE rather than expecting it as a parameter
            JsonObject jsonExtent;
            found = operationInput.TryGetJsonObject("extent", out jsonExtent);
            IGeometry tAnalysisEnvelope;
            if (found && jsonExtent != null)
            {
                logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Found input extent json object ");
                tAnalysisEnvelope = convertAnyJsonGeometry(jsonExtent);
                logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Input extent processed ok ");
                try
                {
                    logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Input extent height*width are: " + tAnalysisEnvelope.Envelope.Height.ToString() + " * " + tAnalysisEnvelope.Envelope.Width.ToString());
                }
                catch (NullReferenceException nre)
                {
                    logger.LogMessage(ServerLogger.msgType.debug, "Processing parameters", 8000, "Problem reading input extent, exception was " + nre.Message + " at " + nre.StackTrace);
                }
            }
            else
            {
                tAnalysisEnvelope = null;
                logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "No input extent parameter requested ");
            }
            List<ExtractionLayerConfig> extractionRequests = new List<ExtractionLayerConfig>();
            foreach (ExtractionLayerConfig tExtLayerInfo in m_ExtractableParams)
            {
                string jsonParam = tExtLayerInfo.ParamName;
                bool? wasRequested;
                found = operationInput.TryGetAsBoolean(jsonParam, out wasRequested);
                if (found && wasRequested.HasValue && (bool)wasRequested)
                {
                    extractionRequests.Add(tExtLayerInfo);
                }
            }
            // check whether to return as json structured object or all flattened onto attributes of the
            // polygon
            bool returnAsPolygonAttributes=false;
            if (extractionRequests.Count > 0)
            {
                bool? nullableBool;
                found = operationInput.TryGetAsBoolean("extractToPolygonAttributes", out nullableBool);
                if (found && nullableBool.HasValue)
                {
                    returnAsPolygonAttributes = (bool)nullableBool;
                }
            }
            #endregion

            #region Do the actual watershed extraction
            // Modified the computeWatershed method to return both the raster and converted polygon versions of the
            // watershed. Because the polygon version, if made by unioning separate polygons, is multipart, and
            // although this is what we want to return to the user, the raster extraction operations can't handle
            // that so we run them with a raster mask input instead. Returning both here saves the extraction methods
            // from converting back to a raster.
            IGeoDataset tWatershedPolyGDS;
            IGeoDataset tWatershedRasterGDS;
            if (tAnalysisEnvelope != null)
            {
                KeyValuePair<IGeoDataset, IGeoDataset> tPair = computeWatershed(locationpoint, tAnalysisEnvelope.Envelope);
                tWatershedPolyGDS = tPair.Value;
                tWatershedRasterGDS = tPair.Key;
            }
//.........这里部分代码省略.........
开发者ID:harry-gibson,项目名称:watershed-soe,代码行数:101,代码来源:WatershedSOE.cs

示例7: SpatialQueryOperationHandler

        private byte[] SpatialQueryOperationHandler(NameValueCollection boundVariables,
                                                  JsonObject operationInput,
                                                      string outputFormat,
                                                      string requestProperties,
                                                  out string responseProperties)
        {
            responseProperties = null; 

            // Deserialize the location.
            JsonObject jsonPoint;
            if (!operationInput.TryGetJsonObject("location", out jsonPoint))
                throw new ArgumentNullException("location");
            IPoint location = Conversion.ToGeometry(jsonPoint,
                esriGeometryType.esriGeometryPoint) as IPoint;
            if (location == null)
                throw new ArgumentException("SpatialQueryREST: invalid location", "location");
            // Deserialize the distance.
            double? distance;
            if (!operationInput.TryGetAsDouble("distance", out distance) || !distance.HasValue)
                throw new ArgumentException("SpatialQueryREST: invalid distance", "distance");
            byte[] result = QueryPoint(location, distance.Value);
            return result;
        }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:23,代码来源:SpatialQueryREST.cs

示例8: FindNearFeatures

    //customLayers/{customLayersID}/findNearFeatures?location=<jsonPoint>&distance=<double>
    private byte[] FindNearFeatures(NameValueCollection boundVariables,
                                   JsonObject operationInput,
                                   string outputFormat,
                                   string requestProperties,
                               out string responseProperties)
    {
      responseProperties = "{\"Content-Type\" : \"application/json\"}";

      //layerID
      int layerID = Convert.ToInt32(boundVariables["customLayersID"]);

      //location
      JsonObject jsonPoint;
      if (!operationInput.TryGetJsonObject("location", out jsonPoint))
        throw new ArgumentNullException("location");

      IPoint location = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
      if (location == null)
        throw new ArgumentException("FindNearFeatures: invalid location", "location");

      //distance
      double? distance;
      if (!operationInput.TryGetAsDouble("distance", out distance) || !distance.HasValue)
        throw new ArgumentException("FindNearFeatures: invalid distance", "distance");

      //execute asking the map server to generate json directly (not an IRecordSet)
      byte[] result = FindNearFeatures(layerID, location, distance.Value);

      return result;
    }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:31,代码来源:NetFindNearFeaturesRESTSOE.cs

示例9: ValidateData

 private byte[] ValidateData(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
 {
     responseProperties = null;
     string validationType;
     bool found = operationInput.TryGetString("validationType", out validationType);
     if (!found || string.IsNullOrEmpty(validationType)) throw new ArgumentNullException("validationType");
     JsonObject data;
     found = operationInput.TryGetJsonObject("data", out data);
     if (!found || (data == null)) throw new ArgumentNullException("data");
     object[] records;
     data.TryGetArray("records", out records);
     string invalidIDs = "";
     if (records.Length > 0) invalidIDs = GetInvalidIDs(records, validationType);
     JsonObject result = new JsonObject();
     result.AddString("validationType", validationType);
     result.AddString("invalidIDs", invalidIDs);
     return Encoding.UTF8.GetBytes(result.ToJson());
 }
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:18,代码来源:InternationalWaterbirdCensusExtensions.cs

示例10: PostData

 private byte[] PostData(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
 {
     responseProperties = null;
     string userID;
     bool found = operationInput.TryGetString("userID", out userID);
     if (!found || string.IsNullOrEmpty(userID)) throw new ArgumentNullException("userID");
     JsonObject data;
     found = operationInput.TryGetJsonObject("data", out data);
     if (!found || (data == null)) throw new ArgumentNullException("data");
     object[] records;
     data.TryGetArray("records", out records);
     int recordsPosted = -1;
     if (records.Length > 0) recordsPosted = PostRecords(records, userID);
     JsonObject result = new JsonObject();
     result.AddLong("recordsPosted", recordsPosted);
     return Encoding.UTF8.GetBytes(result.ToJson());
 }
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:17,代码来源:InternationalWaterbirdCensusExtensions.cs

示例11: GetWISiteSynonyms

 private byte[] GetWISiteSynonyms(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
 {
     responseProperties = null;
     JsonObject data;
     Boolean? excludeWISiteCodes;
     bool found = operationInput.TryGetJsonObject("data", out data);
     if (!found || (data == null)) throw new ArgumentNullException("data");
     found = operationInput.TryGetAsBoolean("excludeWISiteCodes", out excludeWISiteCodes);
     if (!found || (data == null)) throw new ArgumentNullException("excludeWISiteCodes");
     object[] records;
     data.TryGetArray("records", out records);
     JsonObject result = null;
     if (records.Length > 0) result = GetWISynonyms(records, excludeWISiteCodes);
     return Encoding.UTF8.GetBytes(result.ToJson());
 }
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:15,代码来源:InternationalWaterbirdCensusExtensions.cs

示例12: FindNearFeatures

 private byte[] FindNearFeatures(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
 {
     responseProperties = null;
     int layerID = 0;
     JsonObject jsonPoint;
     if (!operationInput.TryGetJsonObject("location", out jsonPoint)) throw new ArgumentNullException("location");
     IPoint location = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
     if (location == null) throw new ArgumentException("FindNearFeatures: invalid location", "location");
     double? distance;
     if (!operationInput.TryGetAsDouble("distance", out distance) || !distance.HasValue) throw new ArgumentException("FindNearFeatures: invalid distance", "distance");
     byte[] result = FindNearFeatures(layerID, location, distance.Value);
     return result;
 }
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:13,代码来源:InternationalWaterbirdCensusExtensions.cs

示例13: Extracthandler

        private byte[] Extracthandler(NameValueCollection boundVariables,
            JsonObject operationInput,
            string outputFormat,
            string requestProperties,
            out string responseProperties)
        {
            responseProperties = null;
            var errors = new ResponseContainer(HttpStatusCode.BadRequest, "");

            string base64Geometry;
            var found = operationInput.TryGetString("geometry", out base64Geometry);

            if (!found || string.IsNullOrEmpty(base64Geometry))
            {
                errors.Message = "geometry parameter is required.";

                return Json(errors);
            }

            JsonObject queryCriteria;
            found = operationInput.TryGetJsonObject("criteria", out queryCriteria);

            if (!found)
            {
                errors.Message = "criteria parameter is required.";

                return Json(errors);
            }

            #if !DEBUG
            _logger.LogMessage(ServerLogger.msgType.infoStandard, "Extracthandler", MessageCode, "Params received");
            #endif

            IGeometry geometry;
            int read;
            var factory = new GeometryEnvironmentClass() as IGeometryFactory3;
            factory.CreateGeometryFromWkbVariant(Convert.FromBase64String(base64Geometry), out geometry, out read);

            var spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            if (geometry.SpatialReference == null)
            {
                //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
                var spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(3857) as ISpatialReferenceResolution;
                spatialReferenceResolution.ConstructFromHorizon();
                var spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
                spatialReferenceTolerance.SetDefaultXYTolerance();
                var spatialReference = spatialReferenceResolution as ISpatialReference;

                geometry.SpatialReference = spatialReference;
            }

            #if !DEBUG
            _logger.LogMessage(ServerLogger.msgType.infoStandard, "Extracthandler", MessageCode, "Geometry converted");
            #endif

            if (geometry.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                var filterGeometry = (ITopologicalOperator4) geometry;
                filterGeometry.IsKnownSimple_2 = false;

                filterGeometry.Simplify();

                if (((IArea)geometry).Area < 0)
                {
                    ((ICurve)geometry).ReverseOrientation();
                }
            }

            var filter = new SpatialFilter
            {
                Geometry = geometry,
                SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            };

            var utmResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(26912) as ISpatialReferenceResolution;
            utmResolution.ConstructFromHorizon();
            var utmTolerance = utmResolution as ISpatialReferenceTolerance;
            utmTolerance.SetDefaultXYTolerance();
            var utmSr = utmResolution as ISpatialReference;

            var notEsri = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(queryCriteria.ToJson());
            var searchResults = new Dictionary<string, IList<IntersectAttributes>>();

            foreach (var keyValue in notEsri)
            {
                var container = _featureClassIndexMap.Single(x => x.Index == int.Parse(keyValue.Key));
                var fields = keyValue.Value.Select(x => x.ToUpper());
                var fieldMap = container.FieldMap.Select(x => x.Value)
                    .Where(y => fields.Contains(y.Field.ToUpper()))
                    .ToList();
            #if !DEBUG
                _logger.LogMessage(ServerLogger.msgType.infoStandard, "Extracthandler", MessageCode, string.Format("Querying {0} at index {1}", container.LayerName, container.Index));
            #endif
                var cursor = container.FeatureClass.Search(filter, true);
                IFeature feature;
                while ((feature = cursor.NextFeature()) != null)
                {
                    var values = new GetValueAtIndexCommand(fieldMap, feature).Execute();
                    var attributes = new IntersectAttributes(values);

//.........这里部分代码省略.........
开发者ID:agrc,项目名称:wri-webapi,代码行数:101,代码来源:wri-soe.cs


注:本文中的JsonObject.TryGetJsonObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。