Execute Intersection Query on Collection of Linestrings where provider is GeometryFeatureProvider

Topics: SharpMap v0.9 / v1.x
Sep 18, 2012 at 9:56 AM

I'm new to SharpMap. First of all, I have only Points in postgis database and I need to connect them to corresponding Lines before doing anything else. I've managed to do that with code like this:

Collection<SharpMap.Geometries.Geometry> trajs = new Collection<SharpMap.Geometries.Geometry>();

            foreach (DataRow dr1 in ds.Tables["userIds"].Rows)
                da = new NpgsqlDataAdapter("SELECT ST_AsText(l.the_geom) as the_geom from locations l where userid="+dr1["userid"].ToString()+";", connStr);
                da.Fill(ds, "trajektorije");

                Collection<SharpMap.Geometries.Point> vertices = new Collection<SharpMap.Geometries.Point>();
                foreach (DataRow dr in ds.Tables["trajektorije"].Rows)
                SharpMap.Geometries.LineString tempTrajs = new SharpMap.Geometries.LineString(vertices);


            TrajectoriesLayer.DataSource = new GeometryFeatureProvider(trajs);

This worked OK, and I showed lines on the map. But later I need to do IntersectionQuery on this layer but this line

TrajectoriesLayer.DataSource.ExecuteIntersectionQuery(poly, fds);

Throws exception "Touches: Not implemented on this geometry type". Can all this be done in some other way?



Sep 18, 2012 at 10:57 AM

SharpMap.Geometries are no longer in use. They only provided limited topology support.

Therefore we have replaced them with NetTopologySuite/GeoAPI geometries. Update your source (or grab it here) and your problems should be gone.

Hth FObermaier

Sep 18, 2012 at 3:15 PM
Edited Sep 18, 2012 at 3:18 PM

Thanks for the aswer. I've replaced some parts of older code with NetTopologySuite/GeoAPI geometries. I have been able to read Points from db and put them in vertices Collection, like shown in code below:

Collection<NetTopologySuite.Geometries.Point> vertices = new Collection<NetTopologySuite.Geometries.Point>();
NetTopologySuite.IO.WKTReader wktReader = new NetTopologySuite.IO.WKTReader();

foreach (DataRow dr in ds.Tables["trajektorije"].Rows)
      vertices.Add((NetTopologySuite.Geometries.Point )wktReader.Read( dr["the_geom"].ToString()));


Everything is ok, I've managed to show these Points on the map (with NTS Provider as DataSource for Layer), and use them in IntersectionQuery with some polygone and it's working.

My problems is that I need to connect these Points and create LineString from them, and then show these Lines on the map (and later do some IntersectionQuery on them, not Points). I can't find a way to do that. This is probably very basic stuff but i am new to NTS...

Sep 19, 2012 at 6:32 AM

I assume you are using a postgis data source? Why don't you use the postgis provider (it is in the SharpMap.Extensions project)?

To create a linstring, you need to have an array of GeoAPI.Coordinates or an GeoAPI.ICoordinateSequence instance. If you have that, you can create your linestring using a GeometryFactory.

var gf = new NetTopologySuite.Geometries.GeometryFactory(/*Maybe an srid value here?*/);
var lineString = gf.CreateLineString(new [] 
        new GeoAPI.Geometries.Coordinate(0, 0),
        new GeoAPI.Geometries.Coordinate(10, 10),

Hth FObermaier