I want to do buffer operation

Topics: General Topics, Algorithms, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Aug 28, 2007 at 2:48 AM
in the sharpmap, there is buffer( ) operation to return Geometries whose distance is less than or equal to given distance. but, how to specify a layer to do this operation ?
Developer
Aug 28, 2007 at 8:05 AM
You need to play with NtsProvider for this kind of operations: http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=NetTopologySuite%20Data%20Provider&referringTitle=Extensions
Aug 28, 2007 at 10:21 AM
thanks D_Guidi, can you give me an example about this ?

i just dont know how to specify a layer to do this operation.

if i do not specify a layer, what result do this operation return ?
Developer
Aug 28, 2007 at 12:01 PM
If you need to filter the geometries that are with a distance of 0.5 mapunits you could use IsWithinDistance:

public ArrayList TrueGeomsIntersect(SharpMap.Data.Providers.ShapeFile sf, SharpMap.Geometries.Geometry isect)
{
ArrayList retval = new ArrayList();

// convert the test geometry to NTS.
GisSharpBlog.NetTopologySuite.Geometries.Geometry isectPt = SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(isect, new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());

//this will filter out all the unreasonable geometries
//before we do more complex intersection testing.
System.Collections.Generic.List ids = sf.GetObjectIDsInView(isect.GetBoundingBox());

// loop through all the candidate geometries (a reduced set,
// from the "filter" we just ran.),test intersection
bool doesIntersect = false;
foreach (uint id in ids)
{
//convert the candidate geometry to NTS
GisSharpBlog.NetTopologySuite.Geometries.Geometry geom = SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(sf.GetGeometryByID(id), new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());
if (geom.IsWithinDistance(isectPt, 0.5))
retval.Add(id);
}
return retval;
}
Aug 29, 2007 at 3:50 AM
thanks D_Guidi
your code is so similar to that example. i have use that example to get polygons which intersected by a linestring.

but, this time. the target layer is a point layer. now,
sf.GetObjectIDsInView(isect.GetBoundingBox());
this code returns geometry Object IDs whose bounding box intersects 'bbox'.
the layer is point, isect is also a point. so the function sf.GetObjectIDsInView(isect.GetBoundingBox()); will make no effect except the coordinates of point on the layer is equal to the given point.

i use your code to test, but the result is incorrect.
my data is the demo data cities.shp
Developer
Aug 29, 2007 at 8:08 AM
Try to delete sf.GetObjectIDsInView(isect.GetBoundingBox()), so you could perform the operation on the entire shapefile
Aug 29, 2007 at 8:59 AM
sharpmap has only used GetObjectIDsInView( ) to get objectID.
if i delete sf.GetObjectIDsInView(isect.GetBoundingBox()), there is no other method to get all objectIDs of entire shapefile.
does sharpmap leck of this method ? such as GetObjectIDInAll( ). return all objectIDs of a shapefile.

D_Guidi, you say "so you could perform the operation on the entire shapefile". but i dont know how. because i can't get all objectIDs.
Developer
Aug 29, 2007 at 12:54 PM
I'm not a SharpMap expert, but you could simply use the current view extents as bbox for retrieve the IDs...