本文整理汇总了C#中SharpMap.ImageToWorld方法的典型用法代码示例。如果您正苦于以下问题:C# SharpMap.ImageToWorld方法的具体用法?C# SharpMap.ImageToWorld怎么用?C# SharpMap.ImageToWorld使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpMap
的用法示例。
在下文中一共展示了SharpMap.ImageToWorld方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFeatureInfoPlain
/// <summary>
/// Gets FeatureInfo as text/plain
/// </summary>
/// <param name="strBBOX">string representation of a boundingbox</param>
/// <returns>Plain text string with featureinfo results</returns>
public static string CreateFeatureInfoPlain(SharpMap.Map map, string[] requestedLayers, Single x, Single y, int featureCount, string cqlFilter)
{
string vstr = "GetFeatureInfo results: \n";
foreach (string requestLayer in requestedLayers)
{
bool found = false;
foreach (ILayer mapLayer in map.Layers)
{
if (String.Equals(mapLayer.LayerName, requestLayer,
StringComparison.InvariantCultureIgnoreCase))
{
found = true;
if (!(mapLayer is ICanQueryLayer)) continue;
ICanQueryLayer queryLayer = mapLayer as ICanQueryLayer;
if (queryLayer.IsQueryEnabled)
{
Single queryBoxMinX = x - (_pixelSensitivity);
Single queryBoxMinY = y - (_pixelSensitivity);
Single queryBoxMaxX = x + (_pixelSensitivity);
Single queryBoxMaxY = y + (_pixelSensitivity);
SharpMap.Geometries.Point minXY = map.ImageToWorld(new System.Drawing.PointF(queryBoxMinX, queryBoxMinY));
SharpMap.Geometries.Point maxXY = map.ImageToWorld(new System.Drawing.PointF(queryBoxMaxX, queryBoxMaxY));
BoundingBox queryBox = new BoundingBox(minXY, maxXY);
SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
if (_intersectDelegate != null)
{
fds.Tables[0] = _intersectDelegate(fds.Tables[0], queryBox);
}
if (fds.Tables.Count == 0)
{
vstr = vstr + "\nSearch returned no results on layer: " + requestLayer;
}
else
{
if (fds.Tables[0].Rows.Count == 0)
{
vstr = vstr + "\nSearch returned no results on layer: " + requestLayer + " ";
}
else
{
//filter the rows with the CQLFilter if one is provided
if (cqlFilter != null)
{
for (int i = fds.Tables[0].Rows.Count - 1; i >= 0; i--)
{
if (!CQLFilter((SharpMap.Data.FeatureDataRow)fds.Tables[0].Rows[i], cqlFilter))
{
fds.Tables[0].Rows.RemoveAt(i);
}
}
}
//if featurecount < fds...count, select smallest bbox, because most likely to be clicked
vstr = vstr + "\n Layer: '" + requestLayer + "'\n Featureinfo:\n";
int[] keys = new int[fds.Tables[0].Rows.Count];
double[] area = new double[fds.Tables[0].Rows.Count];
for (int l = 0; l < fds.Tables[0].Rows.Count; l++)
{
SharpMap.Data.FeatureDataRow fdr = fds.Tables[0].Rows[l] as SharpMap.Data.FeatureDataRow;
area[l] = fdr.Geometry.GetBoundingBox().GetArea();
keys[l] = l;
}
Array.Sort(area, keys);
if (fds.Tables[0].Rows.Count < featureCount)
{
featureCount = fds.Tables[0].Rows.Count;
}
for (int k = 0; k < featureCount; k++)
{
for (int j = 0; j < fds.Tables[0].Rows[keys[k]].ItemArray.Length; j++)
{
vstr = vstr + " '" + fds.Tables[0].Rows[keys[k]].ItemArray[j].ToString() + "'";
}
if ((k + 1) < featureCount)
vstr = vstr + ",\n";
}
}
}
}
}
}
if (found == false)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined,
"Unknown layer '" + requestLayer + "'");
}
}
return vstr;
}
示例2: CreateFeatureInfoGeoJSON
/// <summary>
/// Gets FeatureInfo as GeoJSON
/// </summary>
/// <param name="strBBOX">string representation of a boundingbox</param>
/// <returns>GeoJSON string with featureinfo results</returns>
public static string CreateFeatureInfoGeoJSON(SharpMap.Map map, string[] requestedLayers, Single x, Single y, int featureCount, string cqlFilter)
{
List<SharpMap.Converters.GeoJSON.GeoJSON> items = new List<SharpMap.Converters.GeoJSON.GeoJSON>();
foreach (string requestLayer in requestedLayers)
{
bool found = false;
foreach (ILayer mapLayer in map.Layers)
{
if (String.Equals(mapLayer.LayerName, requestLayer,
StringComparison.InvariantCultureIgnoreCase))
{
found = true;
if (!(mapLayer is ICanQueryLayer)) continue;
ICanQueryLayer queryLayer = mapLayer as ICanQueryLayer;
if (queryLayer.IsQueryEnabled)
{
Single queryBoxMinX = x - (_pixelSensitivity);
Single queryBoxMinY = y - (_pixelSensitivity);
Single queryBoxMaxX = x + (_pixelSensitivity);
Single queryBoxMaxY = y + (_pixelSensitivity);
SharpMap.Geometries.Point minXY = map.ImageToWorld(new System.Drawing.PointF(queryBoxMinX, queryBoxMinY));
SharpMap.Geometries.Point maxXY = map.ImageToWorld(new System.Drawing.PointF(queryBoxMaxX, queryBoxMaxY));
BoundingBox queryBox = new BoundingBox(minXY, maxXY);
SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
//
if (_intersectDelegate != null)
{
fds.Tables[0] = _intersectDelegate(fds.Tables[0], queryBox);
}
//filter the rows with the CQLFilter if one is provided
if (cqlFilter != null)
{
for (int i = fds.Tables[0].Rows.Count-1; i >=0 ; i--)
{
if (!CQLFilter((SharpMap.Data.FeatureDataRow)fds.Tables[0].Rows[i], cqlFilter))
{
fds.Tables[0].Rows.RemoveAt(i);
}
}
}
IEnumerable<SharpMap.Converters.GeoJSON.GeoJSON> data = SharpMap.Converters.GeoJSON.GeoJSONHelper.GetData(fds);
#if DotSpatialProjections
throw new NotImplementedException();
#else
// Reproject geometries if needed
IMathTransform transform = null;
if (queryLayer is VectorLayer)
{
ICoordinateTransformation transformation = (queryLayer as VectorLayer).CoordinateTransformation;
transform = transformation == null ? null : transformation.MathTransform;
}
if (transform != null)
{
data = data.Select(d =>
{
Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform);
d.SetGeometry(converted);
return d;
});
}
#endif
items.AddRange(data);
}
}
}
if (found == false)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined,
"Unknown layer '" + requestLayer + "'");
}
}
StringWriter writer = new StringWriter();
SharpMap.Converters.GeoJSON.GeoJSONWriter.Write(items, writer);
return writer.ToString();
}
示例3: GetFeatureInfo
//.........这里部分代码省略.........
//Set layers on/off
if (context.Request.Params["LAYERS"] != "") //If LAYERS is empty, use all layers
{
string[] layers = context.Request.Params["LAYERS"].Split(new char[] { ',' });
foreach (SharpMap.Layers.ILayer layer in map.Layers)
layer.Enabled = false;
bool layerNotFound = true;
string layerNotFoundName = "";
foreach (string layer in layers)
{
SharpMap.Layers.ILayer lay = map.Layers.Find(delegate(SharpMap.Layers.ILayer findlay) { return findlay.LayerName == layer; });
if (lay == null)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined, "Unknown layer '" + layer + "'");
return;
}
else
{
if (lay is SharpMap.Layers.VectorLayer)
{
lay.Enabled = true;
layerNotFound = false;
}
else
{
lay.Enabled = false;
layerNotFoundName = layer;
}
}
}
if (layerNotFound)
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotQueryable, "No se puede consultar la capa '" + layerNotFoundName + "'");
}
else
{
foreach (SharpMap.Layers.ILayer lay in map.Layers)
{
if (lay is SharpMap.Layers.VectorLayer)
lay.Enabled = true;
else
lay.Enabled = false;
}
}
SharpMap.Geometries.BoundingBox bbox = ParseBBOX(context.Request.Params["bbox"]);
if (bbox == null)
{
WmsException.ThrowWmsException("Invalid parameter BBOX");
return;
}
int w = 0;
int h = 0;
if (!int.TryParse(context.Request.Params["WIDTH"], out w))
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidFormat, "Invalid WIDTH");
if (!int.TryParse(context.Request.Params["HEIGHT"], out h))
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidFormat, "Invalid HEIGHT");
map.Size = new System.Drawing.Size(w, h);
map.ZoomToBox(bbox);
float x = 0;
float y = 0;
if (!float.TryParse(context.Request.Params["X"], System.Globalization.NumberStyles.Float, SharpMap.Map.numberFormat_EnUS, out x))
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidPoint, "Invalid x coordinate");
if (!float.TryParse(context.Request.Params["Y"], System.Globalization.NumberStyles.Float, SharpMap.Map.numberFormat_EnUS, out y))
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidPoint, "Invalid y coordinate");
System.Drawing.PointF ptf = new System.Drawing.PointF(x, y);
SharpMap.Geometries.Point pt = map.ImageToWorld(ptf);
// Para cada layer activo realizo la consulta:
SharpMap.Data.FeatureDataRow fdrow = null;
foreach (SharpMap.Layers.ILayer layer in map.Layers)
{
if (layer.Enabled)
{
SharpMap.Layers.VectorLayer vlayer = layer as SharpMap.Layers.VectorLayer;
vlayer.DataSource.Open();
double distance = 0.0;
fdrow = vlayer.FindGeoNearPoint(pt, 0.1, ref distance);
vlayer.DataSource.Close();
}
}
string response = "";
if (OnProcessWMSGetFeatureInfoResponse != null)
{
response = OnProcessWMSGetFeatureInfoResponse(fdrow, context.Request.Params["INFO_FORMAT"], context.Request.Params["LAYERS"]);
}
context.Response.Clear();
context.Response.ContentType = context.Request.Params["INFO_FORMAT"];
context.Response.Write(response);
context.Response.End();
}