Change projection - Coordinate readout wrong?

Mar 18, 2013 at 1:44 PM
Why is it that if I change the projection to lets say "World Mercator" I can not get any correct coordinate readout anymore?

This was tested with an out of the box downloaded DemoMap 0.11.9.6

I need a projection where circle shapes stay close to their form, but for some reason any other projection than WGS84 seems to break DotSpatial. I tested quite a few.
Mar 18, 2013 at 6:17 PM
The reason is that the function:

public static void ReprojectPoints(double[] xy, double[] z, ProjectionInfo source, double srcZtoMeter, ProjectionInfo dest, double dstZtoMeter, IDatumTransform idt, int startIndex, int numPoints)

in: Reproject.cs

fails to properly reproject coordinates into the Mercator projection. This will create Extents in the million of degrees range which will make DotSpatial explode.

So, anyone know if that reprojection worked before and this is a new bug, or my computer, or does this reprojection in DotSpatial just not work yet in general?

Not working projections so far:

"WGS_1984_Web_Mercator_Auxiliary_Sphere"
"World_Robinson"
"World_Plate_Carree"
"World_Equidistant_Conic"
"North_America_Lambert_Conformal_Conic"
"TransverseMercator.WGS1984lo33"
"Europe_Equidistant_Conic"

Those are all I tested while debugging, so 100% of my tested projections are not working.

Are there actually ones that work or is that intended behaviour?

And if I say work, I mean I can reproject to it and afterwards still use GeoMouseArgs and get a correct Coordinate readout when I hover my mouse over the map. Because without proper reference to coordinates the library is unusable to me. I am still evaluating this for building my software but I don't really get the hang of it yet.
Editor
Mar 19, 2013 at 7:31 AM
WebMercator is by no means a Geographic (lat/lon) coordinate system. It is a projected one and its units is meters.

Hth FObermaier
Mar 19, 2013 at 10:30 AM
Yes, I realize that, and it was not my intention to use it as a coordinate system. In fact, a projection (and the resulting coordinate) for me really is just a way to draw a map, not a way to do math afterwards. I don't even want to see the math, really, it should hide it completely.

---- Problem 1 ----

Hence why I expected that if DotSpatial has a map control and it supports hovering with the mouse cursor over, say, Australia, it would reproject the coordinate before putting it into a structure that is called e.GeographicLocation and return that. I would be fine if there was a second thing named e.ProjectedCoordinate that has it, though.

I mean, what am I supposed to believe what this will return:
        /// <summary>
        /// Gets the position of the Mouse Event in geographic coordinates
        /// </summary>
        public Coordinate GeographicLocation
        {
            get { return _geographicLocation; }
            protected set { _geographicLocation = value; }
        }
A geographic coordinate.. or.... a projected coordinate? It will never contain a geographic coordinate, I can tell you that.

Cause obviously if I hover over Australia I am not really interested in the fact that the projected coordinate is [474152.00 ; 746328.15]. What should I do with that coordinate, really?

---- Problem 2 ----

I also think the map projections should scale about the same for the map display, but the geographic ones obviously are in the -180;180 realm and the projections are just somewhere up in the million range. Of course I can hide that in my code by resetting the zoom after reprojection, but why doesn't DotSpatial handle this transparently already? When I looked at .GeographicExtent i expected to find the... GEOGRAPHIC extent... but its, again, just projected coordinate gibberish.

---- Problem 3 ----

Now, next problem, I have my projected map displayed and I am inserting a Circle at 32°N / 12°W with the radius of 10.
geom = GeometryFactory.Default.CreatePoint(center);
geom = geom.Buffer(10);
feature = fs.AddFeature(geom);
It never shows up in mercator, it doesn't even show up if I reproject the coordinate. I think it's because of the distance calculation. I mean, what is 10? Degrees?

In geographic WGS84, geo.Buffer creates a perfect circle for me, which is not what I expect in WGS84 STD projection because the circle should really be flattened on top cause of longitudinal distortion approaching the poles. So the 10 really is not a distance?

Now, how do I create a circle that really is lets say 100nm around a center point?

Once I switch to mercator the code does not work anymore for me at all, I have no idea what it creates, but its not visible.

If someone needs to calculate and work with projected coordinate systems, thats all fine for me, but I think I should still be able to insert Symbology and polygons using the WGS84 lat/long system and have it project according to the selected projection. And it's not even working if I reproject into mercator manually all the time.

I don't seem to be able to do any of what I need currently, I am even unable to create a circle-area with a specific distance in nm around a point which displays geographically correct.

It should normally be easy with a geospatial library. No idea, I just thought everything should be easier.
Editor
Mar 19, 2013 at 12:09 PM
Edited Mar 19, 2013 at 12:12 PM
  • Problem 1
    This is probably a naming issue. What you are actually getting is not the geographic location but some "world" units that are dependant on the maps projection.
  • Problem 2
    If you want the real geographic location, write yourself a plugin that registers to the GeoMouseMoveEvent and reprojects those coordinates, s.th. along the lines of
    public class Wgs84Location : Extension
    {
        private readonly ProjectionInfo _p = KnownCoordinateSystems.Geographic.World.WGS1984;
        
        public override void Activate()
        {
            base.Activate();
            var map = (Map) App.Map;
            map.GeoMouseMove += MapOnGeoMouseMove;
        }

        private void MapOnGeoMouseMove(object sender, GeoMouseArgs geoMouseArgs)
        {
            var p = geoMouseArgs.Map.Projection;
            var xy = new double[] {geoMouseArgs.X, geoMouseArgs.Y};
            Reproject.ReprojectPoints(xy, null, p, _p, 0, 1);
        }

        public override void Deactivate()
        {
            var map = (Map) App.Map;
            map.GeoMouseMove -= MapOnGeoMouseMove;
            base.Deactivate();
        }
    }
  • Problem 3
    The argument to buffer is dependant on the geometries coordinates. If you have a geographic coordinate and create a buffer with 10, you will get an ellipse with a radius of 10.
    What you need to do to change the projection is:
var geom = GeometryFactory.Default.CreatePoint(center);
geom = geom.Buffer(10);
feature = fs.AddFeature(geom);
fs.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
fs.Reproject( ... );
fs.InvalidateVertices();

//...
I hope there is some truth in this as I have not tested it :)
Hth FObermaier
Mar 19, 2013 at 1:12 PM
Thx for trying, but no it does not work. ;)

If I add a circle in the normal WGS84 it should never be a perfect circle. I tried reprojecting before, after, back and forth... everything.
I have no idea how to get a correct circle projection with DotSpatial. Maybe you can.

I made a graphic to explain my problem.
The lower images are from another software that works correctly, but its a C++ library and I really wanted a .NET library.

All the circles in those graphics are perfectly circular areas around 60°N points with 1000nm radius.
All the rectangles are square areas.

You can see the correct distortion on the lower pictures:

Image
Editor
Mar 19, 2013 at 1:44 PM
Edited Mar 19, 2013 at 1:45 PM
If you create the circle on the WGS84 projection and transform that to Mercator you are bound to fail.
You need to create the circle on the projected coordinate system and transform that to WGS84

AFAIK DotSpatial does not perform any great circle math on geometries.

At least you seem to be getting your projected geometries now :)
Mar 19, 2013 at 4:32 PM
If you create the circle on the WGS84 projection and transform that to Mercator you are bound to fail.
Yes.. I noticed. A circle created on WGS84 is not correct, even in that system, so transforming it into Mercator will further distort an already wrong circle, so yeah its pretty useless.
You need to create the circle on the projected coordinate system and transform that to WGS84
But that also fails. Because...
AFAIK DotSpatial does not perform any great circle math on geometries.
Yes, you are absolutely right! But it should! Cause its the geographically correct way to create a circle area or any area by using distances! :P
I mean this is a library for geospatial data, it's like a core function, at least thats what I thought.

It may work to use a projection where shapes are not distorted, draw a circle and then reproject to WGS84, but then I have to do thousands of reprojections cause i got lots of data. Possible, but very very inefficient.
At least you seem to be getting your projected geometries now :)
Not really... I am getting it for the world shape file, yes... but I am more interested in creation and correct projection of my circle and polygon areas.

I thought that DotSpatial can do all the geographical math for me out of the box, thats why I tried to use it. Of course I can go ahead all learn all the math and do all the coding myself, but it will take time, lots of time.