本文整理汇总了C#中Map.ImageToWorld方法的典型用法代码示例。如果您正苦于以下问题:C# Map.ImageToWorld方法的具体用法?C# Map.ImageToWorld怎么用?C# Map.ImageToWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.ImageToWorld方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRender
protected override void OnRender(Graphics g, Map map)
{
var image = NorthArrowImage ?? DefaultNorthArrowBitmap;
var mapSize = map.Size;
//Get rotation
var ptTop = map.ImageToWorld(new PointF(mapSize.Width/2f, 0f),true);
var ptBottom = map.ImageToWorld(new PointF(mapSize.Width / 2f, mapSize.Height * 0.5f), true);
var dx = ptTop.X - ptBottom.X;
var dy = ptBottom.Y - ptTop.Y;
var length = Math.Sqrt(dx*dx + dy*dy);
var cos = dx/length;
var rot = -90 + (dy > 0 ? -1 : 1) * Math.Acos(cos) / GeoSpatialMath.DegToRad;
var halfSize = new Size((int)(0.5f*Size.Width), (int)(0.5f*Size.Height));
var oldTransform = g.Transform;
var clip = g.ClipBounds;
var newTransform = new Matrix(1f, 0f, 0f, 1f,
clip.Left + halfSize.Width,
clip.Top + halfSize.Height);
newTransform.Rotate((float)rot);
// Setup image attributes
var ia = new ImageAttributes();
var cmap = new [] {
new ColorMap { OldColor = Color.Transparent, NewColor = OpacityColor(BackgroundColor) },
new ColorMap { OldColor = Color.Black, NewColor = OpacityColor(ForeColor) }
};
ia.SetRemapTable( cmap );
g.Transform = newTransform;
var rect = new Rectangle(-halfSize.Width, -halfSize.Height, Size.Width, Size.Height);
g.DrawImage(image, rect, 0, 0, image.Size.Width, image.Size.Height, GraphicsUnit.Pixel, ia);
g.Transform = oldTransform;
}
示例2: OnRender
/// <summary>
/// Function to render the actual map decoration
/// </summary>
/// <param name="g"></param>
/// <param name="map"></param>
protected override void OnRender(Graphics g, Map map)
{
var rectF = g.ClipBounds;
if (MapUnit == (int)Unit.Degree)
{
var p1 = map.ImageToWorld(new PointF(0, map.Size.Height*0.5f));
var p2 = map.ImageToWorld(new PointF(map.Size.Width, map.Size.Height*0.5f));
SetScaleD((int)g.DpiX, p1.X, p2.X, p1.Y, map.Size.Width);
}
else
SetScale((int)g.DpiX, map.Envelope.Width, map.Size.Width);
var rect = new Rectangle(Point.Truncate(rectF.Location), Size.Truncate(rectF.Size));
RenderScaleBar(g, rect);
}
示例3: Tile
private IEnumerable<Envelope> Tile(Map map)
{
var lt = Point.Truncate(map.WorldToImage(map.Envelope.TopLeft()));
var rb = Point.Ceiling(map.WorldToImage(map.Envelope.BottomRight()));
var size = new Size(rb.X - lt.X, rb.Y - lt.Y);
var fullRect = new Rectangle(lt, size);
var overlapSize = new Size(2, 2);
for (var top = lt.Y; top < fullRect.Bottom; top+= TilingSize.Height )
{
for (var left = lt.X; left < fullRect.Right; left += TilingSize.Width)
{
var partialRect = new Rectangle(new Point(left - overlapSize.Width, top - overlapSize.Height),
Size.Add(TilingSize, overlapSize));
var res = new Envelope(map.ImageToWorld(partialRect.Location));
res.ExpandToInclude(map.ImageToWorld(new PointF(partialRect.Right, partialRect.Bottom)));
yield return res;
}
}
}
示例4: ParseQueryString
//.........这里部分代码省略.........
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
if (context.Request.Params["I"] != null)
try
{
x = System.Convert.ToSingle(context.Request.Params["I"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
//same procedure for J (Y)
if (context.Request.Params["Y"] != null)
try
{
y = System.Convert.ToSingle(context.Request.Params["Y"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
if (context.Request.Params["J"] != null)
try
{
y = System.Convert.ToSingle(context.Request.Params["J"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
p = map.ImageToWorld(new System.Drawing.PointF(x, y));
int fc;
try
{
fc = System.Convert.ToInt16(context.Request.Params["FEATURE_COUNT"]);
if (fc < 1)
fc = 1;
}
catch
{
fc = 1;
}
//default to text if an invalid format is requested
string infoFormat = context.Request.Params["INFO_FORMAT"];
string cqlFilter = null;
if (context.Request.Params["CQL_FILTER"] != null)
{
cqlFilter = context.Request.Params["CQL_FILTER"];
}
string vstr = "";
string[] requestLayers = context.Request.Params["QUERY_LAYERS"].Split(new[] { ',' });
if (String.Compare(context.Request.Params["INFO_FORMAT"], "text/json", ignorecase) == 0)
{
vstr = CreateFeatureInfoGeoJSON(map, requestLayers, x, y, fc, cqlFilter);
context.Response.ContentType = "text/json";
}
else
{
vstr = CreateFeatureInfoPlain(map, requestLayers, x, y, fc, cqlFilter);
context.Response.ContentType = "text/plain";
}
context.Response.Clear();
示例5: ImageToWorld_DefaultMap_ReturnValue
public void ImageToWorld_DefaultMap_ReturnValue()
{
var map = new Map(new Size(500, 200)) {Center = GeometryFactory.CreateCoordinate(23, 34), Zoom = 1000};
ICoordinate p = map.ImageToWorld(new PointF(242.5f, 92));
Assert.AreEqual(GeometryFactory.CreateCoordinate(8, 50), p);
}
示例6: ImageToWorld
public void ImageToWorld()
{
Map map = new Map(new Size(1000, 500)) {Zoom = 360, Center = GeometryFactory.CreateCoordinate(0, 0)};
Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0),
map.ImageToWorld(new PointF(500, 250)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, 90),
map.ImageToWorld(new PointF(0, 0)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, -90),
map.ImageToWorld(new PointF(0, 500)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(180, 90),
map.ImageToWorld(new PointF(1000, 0)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(180, -90),
map.ImageToWorld(new PointF(1000, 500)));
}
示例7: CreateFeatureInfoPlain
/// <summary>
/// Gets FeatureInfo as text/plain
/// </summary>
/// <param name="map">The map</param>
/// <param name="requestedLayers">The requested layers</param>
/// <param name="x">The x-ordinate</param>
/// <param name="y">The y-ordinate</param>
/// <param name="featureCount"></param>
/// <param name="cqlFilter">The code query language</param>
/// <param name="context">The <see cref="HttpContext"/> to use. If not specified or <value>null</value>, <see cref="HttpContext.Current"/> is used.</param>
/// <exception cref="InvalidOperationException">Thrown if this function is used without a valid <see cref="HttpContext"/> at hand</exception>
/// <returns>Plain text string with featureinfo results</returns>
public static string CreateFeatureInfoPlain(Map map, string[] requestedLayers, Single x, Single y, int featureCount, string cqlFilter, HttpContext context = null)
{
if (context == null)
context = HttpContext.Current;
if (context == null)
throw new InvalidOperationException("Cannot use CreateFeatureInfoPlain without a valid HttpContext");
var vstr = "GetFeatureInfo results: \n";
foreach (string requestLayer in requestedLayers)
{
bool found = false;
foreach (var mapLayer in map.Layers)
{
if (String.Equals(mapLayer.LayerName, requestLayer,
StringComparison.InvariantCultureIgnoreCase))
{
found = true;
var queryLayer = mapLayer as ICanQueryLayer;
if (queryLayer == null || !queryLayer.IsQueryEnabled) continue;
var queryBoxMinX = x - (_pixelSensitivity);
var queryBoxMinY = y - (_pixelSensitivity);
var queryBoxMaxX = x + (_pixelSensitivity);
var queryBoxMaxY = y + (_pixelSensitivity);
var minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
var maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
var queryBox = new Envelope(minXY, maxXY);
var fds = new FeatureCollectionSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
if (fds.Count == 0)
{
vstr = vstr + "\nSearch returned no results on layer: " + requestLayer;
}
if (_intersectDelegate != null)
{
var fdt = fds[0];
fds.RemoveAt(0);
fds.Add(_intersectDelegate(fdt, queryBox));
}
else
{
if (fds[0].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)
{
var toKeep = fds[0].Clone();
foreach (var f in fds[0])
{
if (!CqlFilter(f, cqlFilter))
{
toKeep.Add(f);
}
}
fds[0] = toKeep;
}
//if featurecount < fds...count, select smallest bbox, because most likely to be clicked
vstr = vstr + "\n Layer: '" + requestLayer + "'\n Featureinfo:\n";
var keys = new object[fds[0].Count];
var area = new double[fds[0].Count];
var l = 0;
foreach (var f in fds[0])
{
area[l] = f.Geometry.EnvelopeInternal.Area;
keys[l] = f.Attributes[0];
}
Array.Sort(area, keys);
if (fds[0].Count < featureCount)
{
featureCount = fds[0].Count;
}
for (int k = 0; k < featureCount; k++)
{
var f = fds[0][keys[k]];
var att = f.Factory.AttributesDefinition;
for (int j = 0; j < att.Count; j++)
{
vstr = vstr + " '" + f.Attributes[j] + "'";
}
if ((k + 1) < featureCount)
vstr = vstr + ",\n";
//.........这里部分代码省略.........
示例8: CreateFeatureInfoGeoJSON
/// <summary>
/// Gets FeatureInfo as GeoJSON
/// </summary>
/// <param name="map">The map to create the feature info from</param>
/// <param name="requestedLayers">The layers to create the feature info for</param>
/// <param name="x">The x-Ordinate</param>
/// <param name="y">The y-Ordinate</param>
/// <param name="featureCount">The number of features</param>
/// <param name="cqlFilterString">The CQL Filter string</param>
/// <param name="context">The <see cref="HttpContext"/> to use. If not specified or <value>null</value>, <see cref="HttpContext.Current"/> is used.</param>
/// <exception cref="InvalidOperationException">Thrown if this function is used without a valid <see cref="HttpContext"/> at hand</exception>
/// <returns>GeoJSON string with featureinfo results</returns>
public static string CreateFeatureInfoGeoJSON(Map map, string[] requestedLayers, Single x, Single y, int featureCount, string cqlFilterString, HttpContext context = null)
{
if (context == null)
context = HttpContext.Current;
if (context == null)
throw new InvalidOperationException("Cannot use CreateFeatureInfoGeoJSON without a valid HttpContext");
var items = new List<Converters.GeoJSON.GeoJSON>();
foreach (var requestLayer in requestedLayers)
{
var found = false;
foreach (var mapLayer in map.Layers)
{
if (String.Equals(mapLayer.LayerName, requestLayer,
StringComparison.InvariantCultureIgnoreCase))
{
found = true;
var queryLayer = mapLayer as ICanQueryLayer;
if (queryLayer == null || !queryLayer.IsQueryEnabled) continue;
var queryBoxMinX = x - (_pixelSensitivity);
var queryBoxMinY = y - (_pixelSensitivity);
var queryBoxMaxX = x + (_pixelSensitivity);
var queryBoxMaxY = y + (_pixelSensitivity);
var minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
var maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
var queryBox = new Envelope(minXY, maxXY);
var fds = new FeatureCollectionSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
//
if (_intersectDelegate != null)
{
var fc = fds[0];
fds.RemoveAt(0);
fds.Add(_intersectDelegate(fc, queryBox));
}
//filter the rows with the CQLFilter if one is provided
if (cqlFilterString != null)
{
var toKeep = fds[0].Clone();
foreach (var f in fds[0].Clone())
{
if (CqlFilter(f, cqlFilterString))
{
toKeep.Add(f);
}
}
fds[0] = toKeep;
}
var data = 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 =>
{
var converted = GeometryTransform.TransformGeometry(d.Geometry, transform, map.Factory);
d.SetGeometry(converted);
return d;
});
}
#endif
items.AddRange(data);
}
}
if (found == false)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined,
"Unknown layer '" + requestLayer + "'", context);
return string.Empty;
}
}
var writer = new StringWriter();
Converters.GeoJSON.GeoJSONWriter.Write(items, writer);
return writer.ToString();
//.........这里部分代码省略.........
示例9: ParseQueryString
//.........这里部分代码省略.........
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
if (context.Request.Params["I"] != null)
try
{
x = System.Convert.ToSingle(context.Request.Params["I"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
//same procedure for J (Y)
if (context.Request.Params["Y"] != null)
try
{
y = System.Convert.ToSingle(context.Request.Params["Y"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
if (context.Request.Params["J"] != null)
try
{
y = System.Convert.ToSingle(context.Request.Params["J"]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameters for I");
}
p = map.ImageToWorld(new System.Drawing.PointF(x, y));
int fc;
try
{
fc = System.Convert.ToInt16(context.Request.Params["FEATURE_COUNT"]);
if (fc < 1)
fc = 1;
}
catch
{
fc = 1;
}
String vstr = "GetFeatureInfo results: \n";
string[] requestLayers = context.Request.Params["QUERY_LAYERS"].Split(new[] { ',' });
foreach (string requestLayer in requestLayers)
{
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));
示例10: ImageToWorld
public void ImageToWorld()
{
Map map = new Map(new System.Drawing.Size(1000, 500));
map.Zoom = 360;
map.Center = GeometryFactory.CreateCoordinate(0, 0);
Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0),
map.ImageToWorld(new System.Drawing.PointF(500, 250)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, 90),
map.ImageToWorld(new System.Drawing.PointF(0, 0)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, -90),
map.ImageToWorld(new System.Drawing.PointF(0, 500)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(180, 90),
map.ImageToWorld(new System.Drawing.PointF(1000, 0)));
Assert.AreEqual(GeometryFactory.CreateCoordinate(180, -90),
map.ImageToWorld(new System.Drawing.PointF(1000, 500)));
}
示例11: ImageToWorld_DefaultMap_ReturnValue
public void ImageToWorld_DefaultMap_ReturnValue()
{
Map map = new Map(new System.Drawing.Size(500, 200));
map.Center = GeometryFactory.CreateCoordinate(23, 34);
map.Zoom = 1000;
ICoordinate p = map.ImageToWorld(new System.Drawing.PointF(242.5f, 92));
Assert.AreEqual(GeometryFactory.CreateCoordinate(8, 50), p);
}
示例12: TryGetData
/// <summary>
/// Check if the layer can be queried and retrieve data, if there is any.
/// </summary>
protected bool TryGetData(Map map,
float x, float y,
int pixelSensitivity,
WmsServer.InterSectDelegate intersectDelegate,
ICanQueryLayer queryLayer,
string cqlFilter,
out IFeatureCollectionSet fds)
{
if (!queryLayer.IsQueryEnabled)
{
fds = null;
return false;
}
float queryBoxMinX = x - pixelSensitivity;
float queryBoxMinY = y - pixelSensitivity;
float queryBoxMaxX = x + pixelSensitivity;
float queryBoxMaxY = y + pixelSensitivity;
Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
Envelope queryBox = new Envelope(minXY, maxXY);
fds = new FeatureCollectionSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
if (fds.Count == 0)
return false;
var table = fds[0];
if (intersectDelegate != null)
{
fds.Remove(table);
fds.Add(intersectDelegate(table, queryBox));
table = fds[0];
}
// filter the rows with the CQLFilter if one is provided
if (cqlFilter != null)
{
var toKeep = table.Clone();
foreach (var feature in table)
{
if (CqlFilter(feature, cqlFilter))
toKeep.Add(feature);
}
fds.Remove(table);
fds.Add(toKeep);
}
return fds[0].Count > 0;
}
示例13: ImageToWorld
public static ICoordinate ImageToWorld(Map map, double width, double height)
{
ICoordinate c1 = map.ImageToWorld(new PointF(0, 0));
ICoordinate c2 = map.ImageToWorld(new PointF((float)width, (float)height));
return GeometryFactory.CreateCoordinate(Math.Abs(c1.X - c2.X), Math.Abs(c1.Y - c2.Y));
}
示例14: TryGetData
/// <summary>
/// Check if the layer can be queried and retrieve data, if there is any.
/// </summary>
protected bool TryGetData(Map map,
float x, float y,
int pixelSensitivity,
WmsServer.InterSectDelegate intersectDelegate,
ICanQueryLayer queryLayer,
string cqlFilter,
out FeatureDataSet fds)
{
if (!queryLayer.IsQueryEnabled)
{
fds = null;
return false;
}
float queryBoxMinX = x - pixelSensitivity;
float queryBoxMinY = y - pixelSensitivity;
float queryBoxMaxX = x + pixelSensitivity;
float queryBoxMaxY = y + pixelSensitivity;
Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
Envelope queryBox = new Envelope(minXY, maxXY);
fds = new FeatureDataSet();
queryLayer.ExecuteIntersectionQuery(queryBox, fds);
FeatureTableCollection tables = fds.Tables;
FeatureDataTable table = tables[0];
if (intersectDelegate != null)
tables[0] = intersectDelegate(table, queryBox);
// filter the rows with the CQLFilter if one is provided
if (cqlFilter != null)
{
DataRowCollection rows = table.Rows;
for (int i = rows.Count - 1; i >= 0; i--)
{
FeatureDataRow row = (FeatureDataRow)rows[i];
bool b = CqlFilter(row, cqlFilter);
if (!b)
rows.RemoveAt(i);
}
}
bool res = tables.Count > 0 && table.Rows.Count > 0;
return res;
}