ThinkGeo.com    |     Documentation    |     Premium Support

Applying rotation to coordinates

Hi, 

My application is built on a homegrown GIS system which is slowly getting migrated over piece by piece to your control. I can rotate shape files successfully to reflect magnetic declination thanks to a previous forum answer.  The problem is I have a layer which is not in the ThinkGeo control and is a WPF canvas which gets text drawn on to it. I am using the following code to get the world coordinates and then translate those to screen coordinates in order to position them properly. This has been working great up until I hit the need to apply the magnetic declination. 




Dim projCoords As Vertex = _projection.ConvertToExternalProjection(pd.Longitude, pd.Latitude)
 
Dim screenCoordinates As PointShape = Map.ToScreenCoordinate(projCoords.X, projCoords.Y)





How do I go about using the rotate projection on the coordinates to get the correct position?



Thank you!



Best,



Kevin

Hi Kevin, 
  
 I was unable to recreate this issue as I can’t get more information about the code you appended here.  
  
 Could you please append more information about this issue, I list them below: 
  
 1. What’s the “pd”? 
 2. How and when the code you append here is called? 
  
 Some code snippets or a sample would be better. 
  
  
 Thanks, 
 Peter

Hi Peter, 



My question is somewhat of a general question about a rotation projection and figuring out screen coordinates. I have a latitude and a longitude which are getting projected to spherical mercator. The airport I’m using in this example has magnetic declination so I need to apply a rotation projection. I can do this fine with feature layers which are in the ThinkGeo control. 



The problem I have is that there is text which is written on a WPF canvas on top of the GIS control. I position this text by using the projected coordinates above and then getting the screen coordinates for those. My question is how do I get the adjusted screen coordinates to take into account the magnetic declination? I am changing setting the current extent on the ThinkGeo map control using the rotation projection’s helper method GetUpdatedExtent but this doesn’t seem to change the coordinates I’m getting back from the control. 



I can provide an example if this still doesn’t make sense. 



Best,



Kevin

Hi Kevin,

Because of the forum migrated, we can’t get the replies from the old forum. As I remember that in the last reply from you said that the idea I provided didn’t resolve the problem you have encountered. Sorry that I don’t understand clearly what your requirements are. Could you please provide us a sample here? I think it will help us quickly to find out the real problem you have encountered.

Thanks,
Peter

Kevin,

After re-project the point to the new projection but before converting the point to the screen coordinate, use the RotateProjection to project it again, Here is the code:

        rotateProjection.Angle = 45;
        wpfMap1.CurrentExtent = rotateProjection.GetUpdatedExtent(new RectangleShape(-200000000, 200000000, 200000000, -200000000));
        wpfMap1.Refresh();         

        Proj4Projection proj4 = new Proj4Projection(4326, 3857);
        proj4.Open();
        PointShape pointShapeInSphericalMercator = (PointShape)proj4.ConvertToExternalProjection(new PointShape(-96.809527, 33.128296));
        PointShape rotatedPointShapeInSphericalMercator = (PointShape)rotateProjection.ConvertToExternalProjection(pointShapeInSphericalMercator);
        PointShape screenShape = wpfMap1.ToScreenCoordinate(rotatedPointShapeInSphericalMercator);
       // Draw the screen point on another canvas on top of the map.
        DrawOnMap(screenShape);

Here is the result image. A point (-96.809527, 33.128296) in Frisco, TX has been converted to Spherical Mercator, and then rotate 45 degrees, locates on the right spot. The yellow rectangle is drawn on another canvas on top of the ThinkGeo Map Control like in your case.

(Seems a glitch in this new forum and I cannot post an image or attachment for now. We will send you the screenshot and code through email.)

Ben

Hi Ben,

That worked great! Thank you very much!

Best,

Kevin

You are welcome, Kevin.