Line-Layer from Database

Topics: Algorithms, Data Access, WinForms Controls
Sep 20, 2013 at 12:08 PM
Hello everyone!

I started exploring SharpMap (great tool, by the way!) and succeded in building layer from database-tables via

layer.DataSource = New SharpMap.Data.Providers.OleDbPoint(connStr, Table$, IDColumn$, XColumn$, YColumn$)

Now i want to build a line-layer from database. Data provides startingpoint / endpoint of the lines to be drawn.

So, how can i build geometries from datatables?
Coordinator
Sep 23, 2013 at 7:46 AM
Where do your point geometries come from, what kind of database is it?
There are a couple of databases that can handle spatial objects (PostGis/SqlServer/SpatiaLite to name a few).
I'm not aware that there is a provider that builds lineal geometries from a table of referenced points. You'd have to do that yourself.

FObermaier
Sep 23, 2013 at 10:37 AM
Hello FObermeier,
Where do your point geometries come from, what kind of database is it?
MS-Access-Tables with UTM32-E32/N32 coordinates of starting- and endingpoint.

You'd have to do that yourself.
Yes, so i have to build a set of line-geometries from the table and set the layer.datasource to it. Are there any code examples that do something similar?
So far i found a way building a Linestring:
    Dim iGeofac As GeoAPI.Geometries.IGeometryFactory
    Dim coLineCoords(2) As GeoAPI.Geometries.Coordinate
    coLineCoords(0) = New GeoAPI.Geometries.Coordinate(rs("E32Oben"), rs("N32Oben"))
    coLineCoords(1) = New GeoAPI.Geometries.Coordinate(rs("E32Unten"), rs("N32Unten"))
    Dim ils As GeoAPI.Geometries.ILineString = iGeofac.CreateLineString(coLineCoords)
I did not find a way to stuff such a linestring into
    Dim colGeom As System.Collections.Generic.IEnumerable(Of GeoAPI.Geometries.IGeometry)
Which would lead me to
    lay.DataSource = New GeometryFeatureProvider(colGeom)
And it all looks as if there should be an easier way to perform the task.

Greatful for hints

Lothar Otto
Coordinator
Sep 23, 2013 at 11:42 AM
MS-Access-Tables with UTM32-E32/N32 coordinates of starting- and endingpoint.
in that case it should be fairly easy to "abuse" the oledbpoint provider
  1. Grab the source of OleDbPoint, rename to OleDbTwoPointLine
  2. Add some property that describes the decorator for point 1 and point 2 (e.g. "{0}Oben", "{0}Unten")
  3. Go through it and see what you have to change in order to get a LineString instead of a Point
var f = Factory;
var x1Column = string.Format(_p1, XColumn); //_p1 = "{0}Oben"
var y1Column = string.Format(_p1, YColumn);
//...
var g = Factory.CreateLineString(new [] { new Coordinate(rs[x1Column], rs[y1Column]), 
                                                            new Coordiante(rs[x2Column], rs[y2Column]) });
Hth FObermaier
Sep 23, 2013 at 3:04 PM
I "abused" it, works fine, thanks a lot.

Interested in the source code?

Greetz
Lothar Otto
Coordinator
Sep 23, 2013 at 3:13 PM
Please feel free to submit a patch
FObermaier