Hello,
i want to place over a standard Webmercator TileAsyncLayer a squared (with 200 meter long edges) frame. The center of this square is specified by a given postion markerPosition.
To get a 200m long edge i had to set edgeLength to 336. I came up with this value by trial and error only.
I verified that this value is roughly valid for all kind of latitudes. How can i properly draw a exact 200m line for Webmercator.
Is using an inverted Haversine formula a good approach: Calculate the 2nd coordinate with the distance and first coordinate given?
int edgeLength = 336;
Coordinate topLeft = new Coordinate(markerPosition.X - 168, markerPosition.Y + 168);
var coords = new Coordinate[5];
coords[0] = topLeft;
coords[1] = new Coordinate(topLeft.X + edgeLength , topLeft.Y);
coords[2] = new Coordinate(coords[1].X, topLeft.Y - edgeLength );
coords[3] = new Coordinate(coords[0].X, coords[2].Y);
coords[4] = topLeft;
IGeometry[] geoms;
geoms = new IGeometry[] { new LineString(coords) };
blueRectangleLayer = new VectorLayer("BlueRectangle")
{
DataSource = new GeometryProvider(geoms),
SRID = 3857,
TargetSRID = 3857
};
blueRectangleLayer.Style.Line.Color = Color.DodgerBlue;
blueRectangleLayer.Style.Line.Width = 2f;
The 2nd problem i am facing is that occasionally i want to place this polygon over a map which uses the EPSG:25833 projection. To achieve that, i use the previously constructed coordinate array and reproject every single coordinate:
IProjectedCoordinateSystem epsg25832 = csFac.CreateFromWkt(wkt25832) as ProjectedCoordinateSystem;
IMathTransform transformation = ctFac.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, epsg25832).MathTransform;
Coordinate topLeft = new Coordinate(markerCenterCoordinate.X - 168, markerCenterCoordinate.Y + 168); ;
var coords = new Coordinate[5];
coords[0] = topLeft;
coords[1] = new Coordinate(topLeft.X + 336, topLeft.Y);
coords[2] = new Coordinate(coords[1].X, topLeft.Y - 336);
coords[3] = new Coordinate(coords[0].X, coords[2].Y);
coords[4] = topLeft;
IGeometry[] geoms;
var coords_t = new Coordinate[5];
for (int i = 0; i < coords.Length; i++)
{
var c = transformation.Transform(coords[i]);
coords_t[i] = c;
}
geoms = new IGeometry[] { new LineString(coords_t) };
//GeometryTransform.TransformPolygon(polygon,)
blueRectangleLayer = CreateGeomLayer("BlueRectangle", geoms, Color.DodgerBlue);
blueRectangleLayer = new VectorLayer("BlueRectangle")
{
DataSource = new GeometryProvider(geoms),
SRID = 25833,
TargetSRID = 25833
};
blueRectangleLayer.Style.Line.Color = Color.DodgerBlue;
blueRectangleLayer.Style.Line.Width = 2f;
But the resulting square is too big. Something is wrong with this approach, but i cannot figure out what. It might be pretty obvious ;)
Hello,
i want to place over a standard Webmercator TileAsyncLayer a squared (with 200 meter long edges) frame. The center of this square is specified by a given postion
markerPosition.To get a 200m long edge i had to set
edgeLengthto 336. I came up with this value by trial and error only.I verified that this value is roughly valid for all kind of latitudes. How can i properly draw a exact 200m line for Webmercator.
Is using an inverted Haversine formula a good approach: Calculate the 2nd coordinate with the distance and first coordinate given?
The 2nd problem i am facing is that occasionally i want to place this polygon over a map which uses the
EPSG:25833projection. To achieve that, i use the previously constructed coordinate array and reproject every single coordinate:But the resulting square is too big. Something is wrong with this approach, but i cannot figure out what. It might be pretty obvious ;)