map zoom

Topics: Algorithms, SharpMap v0.9 / v1.x, WinForms Controls
Jun 29, 2010 at 3:47 PM
Edited Jun 29, 2010 at 4:50 PM


 This will be a easy question

i have a point and i want to zoom to see only 2 kilometers around

 how a can do that ?

 i have try woth this , but this is really to far away  




Point center = new SharpMap.Geometries.Point(x, y);


Geometry buffer = null;


GeometryFactory _geometryFactory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();


//GisSharpBlog.NetTopologySuite.Geometries.Geometry geoBuffer = new GisSharpBlog.NetTopologySuite.Geometries.Geometry(_geometryFactory);


IGeometry geoBuffer = null;


Geometry pointNTS = null;

myMap.Center = center;



pointNTS =

GeometryConverter.ToNTSGeometry(center, _geometryFactory);

pointNTS.SRID = 4326;

geoBuffer = pointNTS.Buffer(2);

buffer =

GeometryConverter.ToSharpMapGeometry(geoBuffer as GisSharpBlog.NetTopologySuite.Geometries.Geometry);



Jun 29, 2010 at 5:03 PM

the buffer i specify seem to be interpreted as degrees instead of meter  what i can do to change this

Jun 29, 2010 at 9:14 PM

Hello longuard,

you need to apply coordinate transformation to your datasources so you get coordinates in a metric system.

Pick a projection that is suitable for the area your data is from, the information how to set up the transformation from wgs84 you can find here.

Hth FObermaier

Jul 6, 2010 at 3:19 PM
Edited Jul 6, 2010 at 3:23 PM

when i try to transform data i have this exeption 

Only 2 dimensions are supported for points

on point.cs ligne 61

Jul 6, 2010 at 3:32 PM

longuard comment out the test for [] length == 2 and the associated throw statement (point.cs 60 and 61). It doesnt take into account points that are created by transformation.

hth jd

Jul 6, 2010 at 3:54 PM
Edited Jul 6, 2010 at 3:59 PM

ok i remove the validation and this work 

but its still missing something to have meters unit 

idont kno what paremter i have to put on created projection

  /// Creates a MTM projection for the northern

/// hemisphere based on the WGS84 datum      

 private IProjectedCoordinateSystem CreateMtmProjection(int mtmZone)      


CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();
    //Create geographic coordinate system based on the WGS84 datum            

IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("WGS 84", 6378137, 298.257223563, LinearUnit.Metre);          

 IHorizontalDatum datum = cFac.CreateHorizontalDatum("WGS_1984", DatumType.HD_Geocentric, ellipsoid, null);          

 IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, datum,              PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),              new AxisInfo("Lat", AxisOrientationEnum.North));

 //Create UTM projection            

List<ProjectionParameter> parameters = new List<ProjectionParameter>(); 

  parameters.Add(new ProjectionParameter("latitude_of_origin", 0));  

parameters.Add(new ProjectionParameter("central_meridian", -70.5 /*183 + 6 * mtmZone*/));  

         parameters.Add(new ProjectionParameter("scale_factor", 0.9999));    

        parameters.Add(new ProjectionParameter("false_easting", 304800));    

        parameters.Add(new ProjectionParameter("false_northing", 0.0));  

 IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters);

return cFac.CreateProjectedCoordinateSystem("WGS 84 / MTM zone " + mtmZone.ToString() + "N", gcs,  projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));      



//Create zone MTM 7 projection                

IProjectedCoordinateSystem mtmProj = CreateMtmProjection(7);

 //Create geographic coordinate system (lets just reuse the CS from the projection)              

 IGeographicCoordinateSystem geoCS = mtmProj.GeographicCoordinateSystem;              

 ICoordinateSystem cs  = SridReader.GetCSbyID(4326);              

 //Create transformation                

CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();                

ICoordinateTransformation transform = ctFac.CreateFromCoordinateSystems(cs, mtmProj);

                //Apply transformation to a vectorlayer              

 myLayer.CoordinateTransformation = transform;

Jul 7, 2010 at 2:47 PM

Hello longuard,

this code snipplet shows you how to use coordinate transformation on single geometries:

        public void TestLonguard()
            // Create zone MTM 7 projection
            SharpMap.CoordinateSystems.IProjectedCoordinateSystem mtmProj = CreateMtmProjection(7);

            // Create geographic coordinate system (lets just reuse the CS from the projection)              
            var geoCS = mtmProj.GeographicCoordinateSystem;
            var cs =
                    "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");

            // Create transformation
            var ctFac = new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory();                
            var transform = ctFac.CreateFromCoordinateSystems(cs, mtmProj);

            // Create transformed geometry
            var geom = new SharpMap.Geometries.Point(transform.MathTransform.Transform(new double[] {0d, 0d}));
            var factory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            var ntsGeom = SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(geom, factory);
            var ntsGeomBuffer = ntsGeom.Buffer(200);

            var geomBuffer = SharpMap.Converters.NTS.GeometryConverter.ToSharpMapGeometry((GisSharpBlog.NetTopologySuite.Geometries.Geometry)ntsGeomBuffer);

            //This might server your purpose
            var bb = geom.GetBoundingBox();
            bb = bb.Grow(200);


        private SharpMap.CoordinateSystems.IProjectedCoordinateSystem CreateMtmProjection(int mtmZone)

            var cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

            //Create geographic coordinate system based on the WGS84 datum            
            var ellipsoid = cFac.CreateFlattenedSphere(
                "WGS 84", 6378137, 298.257223563, SharpMap.CoordinateSystems.LinearUnit.Metre);
            var datum = cFac.CreateHorizontalDatum(
                "WGS_1984", SharpMap.CoordinateSystems.DatumType.HD_Geocentric, ellipsoid, null);
            var gcs = cFac.CreateGeographicCoordinateSystem(
                "WGS 84", SharpMap.CoordinateSystems.AngularUnit.Degrees,
                datum, SharpMap.CoordinateSystems.PrimeMeridian.Greenwich,
                new SharpMap.CoordinateSystems.AxisInfo(
                    "Lon", SharpMap.CoordinateSystems.AxisOrientationEnum.East),
                new SharpMap.CoordinateSystems.AxisInfo(
                    "Lat", SharpMap.CoordinateSystems.AxisOrientationEnum.North));

            //Create UTM projection
            var parameters = new System.Collections.Generic.List<SharpMap.CoordinateSystems.ProjectionParameter>();
            parameters.Add(new SharpMap.CoordinateSystems.ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new SharpMap.CoordinateSystems.ProjectionParameter("central_meridian", -70.5
                               /*183 + 6 * mtmZone*/));
            parameters.Add(new SharpMap.CoordinateSystems.ProjectionParameter("scale_factor", 0.9999));
            parameters.Add(new SharpMap.CoordinateSystems.ProjectionParameter("false_easting", 304800));
            parameters.Add(new SharpMap.CoordinateSystems.ProjectionParameter("false_northing", 0.0));

            var projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters);

            return cFac.CreateProjectedCoordinateSystem(
                "WGS 84 / MTM zone " + mtmZone.ToString() + "N", gcs, projection,
                new SharpMap.CoordinateSystems.AxisInfo("East", 
                new SharpMap.CoordinateSystems.AxisInfo("North", 


You may need to fill in your coordinates. From your previous code post I gather that you might not need to use NTS to create a buffer since all you do with your buffered geometry is to use its BoundingBox to set the viewport. You can achive this simpler and faster with the BoundingBox.Grow() function.

Hth FObermaier


Jul 7, 2010 at 8:27 PM


i can use bb.grow() but how if a enter 200 is not 200 meters or kilometer that add 200 to longitude & lattitude


Jul 7, 2010 at 9:33 PM

Of course you have to apply the defined coordinate transformation to your Layer(s) if you want to pass meters.

cheers FObermaier

Jul 7, 2010 at 9:41 PM
Edited Jul 7, 2010 at 9:41 PM

there is no other way to calculate meters or to find degrees coresponding to x meters


Jul 7, 2010 at 9:53 PM

see this, chapter "Destination point given distance and bearing from start point"

If you use a bearing of 90° or 270° you should get your grow parameters.

hth FObermaier

Jul 7, 2010 at 9:59 PM


Jul 12, 2010 at 1:08 PM

i have make a try to tramform layer with a metric projection  32198 instead of 4326

32198;PROJCS["NAD83 / Quebec Lambert",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",60],PARAMETER["standard_parallel_2",46],PARAMETER["latitude_of_origin",44],PARAMETER["central_meridian",-68.5],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32198"]]

and when i user boudingbox.grow or buffer the factor added is still not considered as meters

tere is something i forget to do ....