本文整理汇总了C#中JsonObject.TryGetAsDouble方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.TryGetAsDouble方法的具体用法?C# JsonObject.TryGetAsDouble怎么用?C# JsonObject.TryGetAsDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.TryGetAsDouble方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handler
/// <summary>
/// Handles the incoming rest requests
/// </summary>
/// <param name="boundVariables"> The bound variables. </param>
/// <param name="operationInput"> The operation input. </param>
/// <param name="outputFormat"> The output format. </param>
/// <param name="requestProperties"> The request properties. </param>
/// <param name="responseProperties"> The response properties. </param>
/// <returns> </returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
string outputFormat, string requestProperties,
out string responseProperties)
{
responseProperties = null;
var errors = new ErrorModel(400);
object[] geometryJson;
var found = operationInput.TryGetArray("geometry", out geometryJson);
if (!found || geometryJson.Length < 1)
errors.Message += "Value cannot be null: {0}. ".With("geometry");
double? durationThreshold;
found = operationInput.TryGetAsDouble("durationThreshold", out durationThreshold);
if (!found || !durationThreshold.HasValue)
durationThreshold = 0;
if (errors.HasErrors)
return Json(new ErrorContainer(errors));
var areaOfInterest = new AreaOfInterest
{
PointCollection = geometryJson.Cast<decimal>().ToList()
};
IPolygon4 polygon;
try
{
polygon = CommandExecutor.ExecuteCommand(new BuildPolygonFromPointsCommand(areaOfInterest));
}
catch (Exception ex)
{
errors.Message += ex.Message;
return Json(new ErrorContainer(errors));
}
SolarPotential solarValues = null;
try
{
solarValues =
CommandExecutor.ExecuteCommand(new GetSolarPotentialCommand(polygon,
ApplicationCache.PropertyValueIndexMap,
durationThreshold.GetValueOrDefault(0)));
}
catch (Exception ex)
{
errors.Message += ex.Message;
}
return Json(new SolarContainer(solarValues));
}
示例2: 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;
}
示例3: 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
示例4: 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;
}
示例5: Handler
public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
double? milepost;
var found = operationInput.TryGetAsDouble("milepost", out milepost);
if (!found || !milepost.HasValue)
{
throw new ArgumentNullException("milepost");
}
double? routeNumber;
found = operationInput.TryGetAsDouble("routeNumber", out routeNumber);
if (!found || !routeNumber.HasValue)
{
throw new ArgumentNullException("routeNumber");
}
string routeType;
found = operationInput.TryGetString("routeType", out routeType);
if (!found || string.IsNullOrEmpty(routeType))
{
throw new ArgumentNullException("routeType");
}
var connector = SdeConnectorFactory.Create(LayerName);
if (connector == null)
{
return Json(new
{
Message = "Database does not exist for {0}".With(LayerName)
});
}
var workspace = connector.Connect();
var featureWorkSpace = workspace as IFeatureWorkspace;
if (featureWorkSpace == null)
{
return Json(new
{
Message = "Error connecting to SDE."
});
}
var response =
CommandExecutor.ExecuteCommand(
new FindRouteMilepostCommand(milepost.Value.ToString(CultureInfo.InvariantCulture), routeType,
routeNumber.Value.ToString("0000"), LayerName,
featureWorkSpace));
if (response == null)
{
return Json(new
{
Message =
"No mile post found for {0} on route {1}{2}".With(milepost, routeNumber, routeType)
});
}
return Json(response);
}
示例6: getSpeciesListForQuadkeyHandler
private byte[] getSpeciesListForQuadkeyHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
string quadkey;
double? quadkeydbl; //the quadkey is converted to a number by json so we must get it as a number - e.g. 132320330230023
operationInput.TryGetAsDouble("quadkey", out quadkeydbl); //get the quadkey
quadkey = quadkeydbl.ToString(); //convert to a string
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); //open a connection to the species data table
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IWorkspace workspace = workspaceFactory.OpenFromFile("D:\\GIS Data\\Andrew\\PilotSpeciesData.gdb", 0); //TODO make this more sustainable
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IQueryDef queryDef = featureWorkspace.CreateQueryDef(); //create a query to get the data
queryDef.Tables = "PilotSpeciesData,Species"; //specify the tables
queryDef.SubFields = "PilotSpeciesData.species_ID,Species.tax_id,Species.friendly_name"; //specify the fields that you will return
queryDef.WhereClause = "PilotSpeciesData.quadkey='" + quadkey + "' and PilotSpeciesData.species_ID=Species.tax_id"; //create the query
ICursor cursor = queryDef.Evaluate();
int friendly_nameIndex = cursor.FindField("Species.friendly_name");
IRow row = null;
String s = "";
while ((row = cursor.NextRow()) != null) //get the resultset and iterate through the records
{
s = s + row.get_Value(friendly_nameIndex) + ",";
}
JsonObject result = new JsonObject();
result.AddString("species", s); //write the results
return Encoding.UTF8.GetBytes(result.ToJson()); //return the results
}
示例7: Handler
/// <summary>
/// Handles the incoming rest requests
/// </summary>
/// <param name="boundVariables"> The bound variables. </param>
/// <param name="operationInput"> The operation input. </param>
/// <param name="outputFormat"> The output format. </param>
/// <param name="requestProperties"> The request properties. </param>
/// <param name="responseProperties"> The response properties. </param>
/// <returns> </returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
string outputFormat, string requestProperties,
out string responseProperties)
{
responseProperties = null;
var errors = new ErrorModel(400);
string layerName;
double? utmx, utmy;
object[] attributeListObj;
var found = operationInput.TryGetString("layerName", out layerName);
if (!found || string.IsNullOrEmpty(layerName))
{
throw new ArgumentNullException("layerName");
}
found = operationInput.TryGetAsDouble("utmx", out utmx);
if (!found || !utmx.HasValue)
{
throw new ArgumentNullException("utmx");
}
found = operationInput.TryGetAsDouble("utmy", out utmy);
if (!found || !utmy.HasValue)
{
throw new ArgumentNullException("utmy");
}
found = operationInput.TryGetArray("attributeList", out attributeListObj);
if (!found || attributeListObj == null || attributeListObj.Length < 1)
{
throw new ArgumentNullException("attributeList");
}
var attributeList = attributeListObj.Cast<string>().ToArray();
var searchArgs = new PointInPolyArgs(layerName, utmx.Value, utmy.Value, attributeList);
var connector = SdeConnectorFactory.Create(layerName);
if (connector == null)
{
return Json(new
{
Message = "Database does not exist for {0}".With(layerName)
});
}
var workspace = connector.Connect();
var featureWorkSpace = workspace as IFeatureWorkspace;
if (featureWorkSpace == null)
{
return Json(new
{
Message = "Error connecting to SDE."
});
}
var response = CommandExecutor.ExecuteCommand(new PointInPolygoinQueryCommand(searchArgs, featureWorkSpace));
if (response == null)
{
return Json(new
{
Message = "No features found in {2} at the location {0}, {1}.".With(
searchArgs.Point.X, searchArgs.Point.Y, searchArgs.LayerName)
});
}
return Json(response);
}
示例8: QueryRasterHandler
private byte[] QueryRasterHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
int layerID = Convert.ToInt32(boundVariables["layersID"]);
double? min = null;
double? max = null;
operationInput.TryGetAsDouble("min", out min);
operationInput.TryGetAsDouble("max", out max);
if ((!min.HasValue) && (!max.HasValue)) {
throw new ArgumentException(Name + ": must specify at least one of {min,max}");
}
ISpatialReference outSR = GetSpatialReferenceParam(operationInput, "outSR");
IRaster raster = m_layers[layerID].Raster;
IRasterBand band = (raster as IRasterBandCollection).Item(0);
IRawPixels pixels = band as IRawPixels;
IRasterProps properties = band as IRasterProps;
int width = properties.Width;
int height = properties.Height;
double noData = Convert.ToDouble(properties.NoDataValue);
IPnt flowDirBlockSize = new Pnt();
flowDirBlockSize.SetCoords(width, height);
IPixelBlock pixelBlock = raster.CreatePixelBlock(flowDirBlockSize);
IPnt pixelOrigin = new Pnt();
pixelOrigin.SetCoords(0, 0);
pixels.Read(pixelOrigin, pixelBlock);
System.Array data = (System.Array)(pixelBlock as IPixelBlock3).get_PixelDataByRef(0);
bool[,] outData = new bool[width, height];
for (int x = 0; x < width; x += 1) {
for (int y = 0; y < height; y += 1) {
object value = data.GetValue(x, y);
bool cellValue = false;
if (value != null) {
double numericValue = Convert.ToDouble(value);
if ((numericValue != noData) &&
((!min.HasValue) || (numericValue > min.Value)) &&
((!max.HasValue) || (numericValue < max.Value))) {
cellValue = true;
}
}
outData.SetValue(cellValue, x, y);
}
}
BoundingCurve bc = new BoundingCurve(outData);
IPolygon resultGeom = bc.GetBoundaryAsPolygon(properties);
resultGeom.SpatialReference = properties.SpatialReference;
if ((outSR != null) && (outSR.FactoryCode != resultGeom.SpatialReference.FactoryCode)) {
resultGeom.Project(outSR);
}
Feature resultFeature = new Feature();
resultFeature.Geometry = resultGeom;
resultFeature.Attributes.Add("Shape_Length", resultGeom.Length);
resultFeature.Attributes.Add("Shape_Area", (resultGeom as IArea).Area);
resultFeature.Attributes.Add("Shape_Units", DescribeUnits(resultGeom.SpatialReference));
FeatureSet result = new FeatureSet();
result.GeometryType = esriGeometryType.esriGeometryPolygon;
result.Features.Add(resultFeature);
return Encoding.UTF8.GetBytes(result.ToJsonObject().ToJson());
}
示例9: Handler
/// <summary>
/// Handles the incoming rest requests
/// </summary>
/// <param name="boundVariables"> The bound variables. </param>
/// <param name="operationInput"> The operation input. </param>
/// <param name="outputFormat"> The output format. </param>
/// <param name="requestProperties"> The request properties. </param>
/// <param name="responseProperties"> The response properties. </param>
/// <returns> </returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
string outputFormat, string requestProperties,
out string responseProperties)
{
responseProperties = null;
var errors = new ErrorModel(400);
string layerName;
double? utmx, utmy;
var found = operationInput.TryGetString("layerName", out layerName);
if (!found || string.IsNullOrEmpty(layerName))
{
throw new ArgumentNullException("layerName");
}
found = operationInput.TryGetAsDouble("utmx", out utmx);
if (!found || !utmx.HasValue)
{
throw new ArgumentNullException("utmx");
}
found = operationInput.TryGetAsDouble("utmy", out utmy);
if (!found || !utmy.HasValue)
{
throw new ArgumentNullException("utmy");
}
var connector = SdeConnectorFactory.Create(layerName);
if (connector == null)
{
return Json(new
{
Message = "Database does not exist for {0}".With(layerName)
});
}
var workspace = connector.Connect();
var featureWorkSpace = workspace as IFeatureWorkspace;
if (featureWorkSpace == null)
{
errors.Message = "Error connecting to SDE.";
return Json(errors);
}
var rasterArgs = new RasterArgs(layerName, utmx, utmy);
var response =
CommandExecutor.ExecuteCommand(new GetValueFromRasterCommand(rasterArgs,
featureWorkSpace as IRasterWorkspaceEx));
if (response == null)
{
errors.Message = "No features found in {2} at the location {0}, {1}.".With(
rasterArgs.X, rasterArgs.Y, rasterArgs.LayerName);
return Json(errors);
}
return Json(response);
}