Focus on a specific area with latitude/longitude

Dec 3, 2009 at 10:22 AM

hi
i want to focus desired location in mapControl by giving longitude and latitude as input
It has the ability to focus on a specific area ?


Coordinator
Dec 4, 2009 at 1:21 PM

Hi qasem,

To center the map on a position you can use:

mapControl1.Transform.Center = new BTPoint(629816, 6805085);

However, the center you specify here needs to be in the coordinate system of the of the map. In most of the samples I use this is in SphericalMercator (epsg:3785). So if you have a point in LonLat you need to convert is to SphericalMercator. There is no functionality for projection in the current version. The plan is to use SharpMap's projection for this and integrate it in BruTile. The sample project here: http://www.codeplex.com/ProjNET has an aspx page which happens to show how to do the projection you need. 

Good luck, and let me know if it works. 

btw, which platform do you use?

Paul

Dec 6, 2009 at 7:30 PM

hi Paul :)

Thank you for helping me

i m use windows application

I also wpf and silverlight to try

Thanks again for developing this nice project . good luck

Dec 9, 2009 at 8:27 PM
Edited Dec 9, 2009 at 8:29 PM

Hi ...

This code worked for me

i'm using this WKT EPSG:3395

http://www.spatialreference.org/ref/epsg/3395/

PROJCS["Mercator_2SP",GEOGCS["unnamed ellipse",DATUM["D_unknown",SPHEROID["Unknown",6378137,0]],

PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Mercator_2SP"],

PARAMETER["standard_parallel_1",0],PARAMETER["central_meridian",0],PARAMETER["latitude_of_origin",0],

PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]

This article will help me too:)
 

http://www.sharpgis.net/post/2006/07/07/Applying-on-the-fly-transformation-in-SharpMap.aspx

/// <summary>
    /// Create coordinatesystem based on a Well-Known text
    /// </summary>
    /// <param name="wkt"></param>
    /// <returns></returns>
    private ICoordinateSystem CreateCoordinateSystemFromWKT(string wkt)
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();
        return cFac.CreateFromWkt(wkt);
    }
....
....
....

        IProjectedCoordinateSystem utmProj =(IProjectedCoordinateSystem) CreateCoordinateSystemFromWKT(WKM_string);
        //Create geographic coordinate system (lets just reuse the CS from the projection)
        IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem;
        //Create transformation
        CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
        ICoordinateTransformation trans = ctFac.CreateFromCoordinateSystems(geoCS, utmProj);
        double[] fromPoint = new double[] { 51.422539 , 35.709026};
        double[] toPoint = trans.MathTransform.Transform(fromPoint);
        
     mapControl1.Transform.Center = new Point((int)toPoint[0], (int)toPoint[1]);


 

 


Coordinator
Dec 10, 2009 at 10:10 AM

Thanks for posting this back!

Did spherical mercator (epsg 3785 or 900913) not work for you?

Paul.

Dec 10, 2009 at 1:29 PM

hi

900913 did not test , but 3785 did not work correctly for me


Coordinator
Dec 10, 2009 at 2:29 PM

okay, and what kind of background data did you use?

Paul.

Dec 10, 2009 at 4:55 PM
pauldendulk wrote:

okay, and what kind of background data did you use?

Paul.

I do not understand your purpose!!!

But if you mean this is what was my source for the conversion

i must say,I use the WGS 84 That is read from the GPS device

Excuse me , my English is poor :)

Coordinator
Dec 11, 2009 at 11:43 AM

I expected that 3785 would work for the OSM, Bing or Google backgrounds that are mostly used. So I am trying to figure out where I was wrong, maybe you use a differend background layer, that is why I asked. 

I just download the proj.net project and saw that 3785 was not supported yet. It still uses the old 900913 espg. So that is probably why it didnt work for you.

Paul. 

Dec 11, 2009 at 1:43 PM

Yes I know proj.net does not yet supported.
So I tried to find the WKT 3785,

PROJCS["Popular Visualisation CRS / Mercator", GEOGCS["Popular Visualisation CRS", DATUM["Popular Visualisation Datum", SPHEROID["Popular Visualisation Sphere", 6378137, 0, AUTHORITY["EPSG",7059]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY["EPSG",6055]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9102"]], AXIS["E", EAST], AXIS["N", NORTH], AUTHORITY["EPSG",4055]], PROJECTION["Mercator"], PARAMETER["False_Easting", 0], PARAMETER["False_Northing", 0], PARAMETER["Central_Meridian", 0], PARAMETER["Latitude_of_origin", 0], UNIT["metre", 1, AUTHORITY["EPSG", "9001"]], AXIS["East", EAST], AXIS["North", NORTH], AUTHORITY["EPSG",3785]]

Unfortunately, this does not work for me

So I found WKT  3395, that worked for me  in the background of "OSM" and "Google" and "Bing"

900913 still did not test