This project has moved and is read-only. For the latest updates, please go here.

Buffer LineString in Meters?

Topics: Español, SharpMap Project
Nov 21, 2008 at 7:40 PM
Edited Nov 21, 2008 at 8:13 PM
Hi, my name is Nicolas. I've been working in a company for a few years, using Mapinfo Mapx. I am trying to use Sharpmap & NTS for a new project.
Using MapX, when I needed to create a buffer from a polyline, it was really simple:

map.FeatureFactory.BufferFeatures(line, distance,

MapUnitConstants.miUnitMeter, resolution);

where line is the feature to buffer, distance is the buffer radius in the unit specified, and resolution is the number of nodes per circle in a buffer operation.
My problem is, how can I achieve the same using sharpmap & NTS? Specifically, how can I specify the distance in Meters (as my application requires).
I've tried the following:

line = new LineString(new ICoordinate[] { new Coordinate(-58.7, -34.6), new Coordinate(-58.4, -34.6) });


Geometry buffer = line.Buffer( distance  );

but I dont know how to specify the Unit to meters for the distance parameter in Buffer method. (I mean, the coordinates are in lat/lon but the distance must be in meters).
Currently, I dont need to visualize the resulting buffer, just get the buffer.Coordinates (as i'm planning to use google maps to draw the resulting polygon).

Please, I really need a hand on this, as I've been trying a lot but I can't make it.  :)

(And if someone can provide me a sample code, that would be great! )


La consulta es como crear un buffer de una polilinea, especificando la distancia en metros, y las coordenadas en latitud/longitud.
Intenté, pero no pude lograrlo, si alguien me puede ayudar se lo agradeceré mucho!

También pueden responder en español si lo desean!! Gracias!!


Nov 22, 2008 at 9:15 AM
NTS/SharpMap coordinates measures depends on SRID, so if you use data with a spatial reference in meters you're actually work with meters.
Nov 25, 2008 at 3:16 AM
Thanks Diego for your reply.

What i'm trying to do, is to let a user draw a line using Google Maps API. Then, apply an X meters buffer (let's say 100 meters) and check if a person carrying a gps device enters or exits the buffered zone.

So, correct me if I'm wrong:

1- I should convert the lat/lon coordinates received from the google maps application (for example, (-58.7, -34.6) - (-58.4, -34.6)  ) to a spatial reference in meters
2- Create the linestring using the trasformed coordinates.
3- Make the buffer operation with the linestring.
3- Transform the coordinates from the buffer object back to lat/lon WGS84, so I can compare with GPS data and draw with google maps api.

Am I right ? If so, how can I make this transformation?    What spatial reference do you suggest using for the buffering process, considering that i want to make the application work in different countries (spain, mexico, argentina, by now).

I've looked at the TransformTests demo (inside the WebDemo), and I have tested doing some simple point transformations, but I would really really appreciate a code sample for this please!
Thanks in advance!
Nov 26, 2008 at 4:34 AM
Ok, I was finally able to make this work. This is the code i'm using for the previous example [Linestring (-58.7, -34.6) - (-58.4, -34.6)]

Now, I just need to choose the right utm zone for the linestring's centroid.  Any suggestion and/or will be well received :)

I forgot to tell you before: Thanks for the great work you're doing with this projects!! =)

CoordinateSystemFactory cFac = new CoordinateSystemFactory();


// Source Coordinate System

ICoordinateSystem wgs84 = cFac.CreateFromWkt(

  @"GEOGCS[""Lat Long WGS84"",DATUM[""D_WGS84""," +

  @"SPHEROID[""World_Geodetic_System_of_1984"",6378137.0,298.257222932867]]," +



// Destination Coordinate System

string str = @"PROJCS[""WGS 84 / UTM zone 21S"",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""]]," +

             @"PROJECTION[""Transverse_Mercator""],PARAMETER[""latitude_of_origin"",0]," +

             @"PARAMETER[""central_meridian"",-57],PARAMETER[""scale_factor"",0.9996]," +

             @"PARAMETER[""false_easting"",500000],PARAMETER[""false_northing"",10000000]," +


ICoordinateSystem coordsys = cFac.CreateFromWkt(str);


ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(wgs84, coordsys);


LineString line = new LineString(new Coordinate[] { new Coordinate(-58.7, -34.6), new Coordinate(-58.4, -34.6) });

line = (LineString)GeometryTransform.TransformGeometry(line, trans.MathTransform);


Polygon buffer = (Polygon)line.Buffer(400);

buffer = (Polygon)GeometryTransform.TransformGeometry(buffer, trans.MathTransform.Inverse());