SharpMap Function

Topics: SharpMap v0.9 / v1.x
Oct 21, 2010 at 3:28 AM

I had a fleet tracking app running and almost out of beta when Geoframeworks closed the doors. I have been scrambling ever since to find an alternate .Net GIS library. Can SharpMap have the frunctionality to allow me to display a map, plot some icons and move them around based upon Lat\Longs being feed from a SQL datanbase?  If so, can you advise me of any code samples that can get me started?

 

Thanks

Chuck

Editor
Oct 21, 2010 at 7:39 AM

Hi!

Yes, SharpMap is capable of rendering points as markers. As for animating their position you will need to take care of that yourself. Here are some common examples to get you started: http://sharpmap.codeplex.com/wikipage?title=How%20to...&referringTitle=Documentation

Specifically: http://sharpmap.codeplex.com/wikipage?title=Render%20a%20set%20of%20points%20from%20a%20database%20with%20X%20and%20Y%20columns&referringTitle=How%20to...

Goran

Oct 22, 2010 at 2:50 PM

Thanks Goran,

I have looked at the links.I understand that I have to add the logic to animate the "Markers" but I'm confused at to what do I accomplish with assigning a datasource to the Layer? Would each vehicle in my case be a different layer?

 

SharpMap.Layers.VectorLayer layVehicles = new SharpMap.Layers.VectorLayer("Vehicle");  

 

myMap.Layers.Add(layVehicles);

 

Thanks

 Chuck

 

layVehicles.DataSource = new SharpMap.Data.Providers.MsSql(ConnStr, "myTable", "the_geom", "32632");  

Editor
Oct 22, 2010 at 6:42 PM

Hi!

Your vehicle layer should probably hold all vehicles.

As to datasource - are you updating vehicle positions in the db? If so you will need to periodically reload features from the db. 

Basically datasource is used whenever map is drawn. SM iterates through all (visible) layers and lets them render themselves. Render method and uses datasource to fetch visible data (features that are visible within the view) and renders the appropriate result. 

Btw. which SM build are you using?

Goran

Oct 26, 2010 at 1:22 AM

I'm using the version 0.9 I believe. Is there a later one?

 

I have not yet figured out what SM function to use to set the positioning for a particular vehicle. I have a table containing vehicleID and lat, long and date\time that I plan on feeding the looping logic setting the position each iteration. This is the method I used for GIS.Net 3.0 and it work fine.

Coordinator
Oct 26, 2010 at 1:24 PM

hello csalerno,

i just submitted a patch (7194) that may serve your purpose. You need to update your source for it to work

Hth FObermaier

Oct 27, 2010 at 5:11 PM

Thank you for the heads up FObermaier, but could you be more specific on what changes would help me? Any sample code you could ldirect me too in regards to moving an icon across a map using the data in my table would be great.

 

Thanks

Chuck

Coordinator
Oct 27, 2010 at 8:13 PM

Hello Chuck,

If you were able to apply the patch file and managed to compile the sharpmap solution, run winformsamples and click on ShapeFile radio button twice.

You will see an osm data map with a car moving around. The code is in the WinFormSamples\Samples\ShapeFileSampleOsm.cs file.

Basically the Map object has a second LayerCollection for variable Layers, e.g. Layers whose content changes frequently. It is called VariableLayers and is of type VariableLayersCollection.
It is derived from LayersCollection and has an Interval property in which it asks for requery. The MapImage control splits the map in a static and a variable component. The variable
component is updated every interval and the MapImage.Image property is set to the overlay of static and variable.

Hth FObermaier

 

Oct 27, 2010 at 10:52 PM

Thank you! Thank You!

 

Finaly stupid question.  Is there a way to merge your patch  in TFS 2010?

 

 

Chuck

Coordinator
Oct 27, 2010 at 11:10 PM
Edited Oct 27, 2010 at 11:13 PM

I use TortoiseSVN for things like this, or do you want me to add it to the codeplex repository?

cheers FObermaier

Oct 28, 2010 at 4:56 AM

Well, I manually applied the patchs and I seem to be missing the

VariableLayerCollection.cs & LayerCollectionType class files. Are they part of the patch or was it part of the 78963 build?

 

 Thanks

 Chuck

 

 

 

Coordinator
Oct 28, 2010 at 7:52 AM
Edited Oct 28, 2010 at 7:58 AM

Sorry about that, I seem to have missed that.

I'll update the patch ASAP (7206). I included the missing file in the zip-file.

I suggest you get yourself a copy of tortoisesvn, it makes applying patches so easy.

Cheers FObermaier

Oct 31, 2010 at 5:16 AM

Thanks again for your help FObermaier,

I have gotten the patch applied and the demo working but I can't find the actual code that pulls the positions from a table and moves the car image around. Is the cars' movement sourced from position data?

 

Thanks

Coordinator
Oct 31, 2010 at 10:36 AM

chuck,

it is in the ShapeFileSampleOsm, a nested class called ShapeProvider which is derived from ShapeFile.

You will certainly have to create something different for your solution, maybe based on DataTablePoint provider

Hth FObermaier

Nov 1, 2010 at 5:23 PM

FObermaier,

In following your suggestion I have the below code snippet to setup the Vehicle layer and add a datasource from my SQL Table. I got the code from the example given for a XLS file.

This all leads to a number of questions.

Do I need to pass into the DataTablePoint a populated dataset or datatable? If I just pass in the tablename, where does the connectionstring come from?

Does SharpMap perform the row by row increment of the data table to perform the movement?

 

//Specifing true will save the spatial index to a file which will make it load quicker the next time 

var GPSLogProvider = new SharpMap.Data.Providers.DataTablePoint(ctrlTable.GPSSet, "ID", "dblLatitude", "dblLongitude" );

 

 var layVehicles = new SharpMap.Layers.VectorLayer("test"

, GPSLogProvider);

layVehicles.SRID = 33166;

layVehicles.DataSource.Open();

myMap.VariableLayers.Interval = IntervalValue;

myMap.VariableLayers.Add(layVehicles);

GPSLogProvider.DefinitionQuery = SQLQueryDef;

 //Create Layer for Vehicles

Coordinator
Nov 1, 2010 at 7:32 PM

Hello Chuck,

If your data is on an SQLServer I would not use the datatablepoint provider but go for SqlServer2008 or OleDbPoint. The conncection string in that case is an argument to the constructor. You can pass a view instead of a table name that e.g. just return the currently valid locations.

Hth FObermaier

Nov 3, 2010 at 12:34 PM

 

 

So I have the Provider setup for my SQL Call and able to populate a Bbox struct but not clear how the DataSet rows from the FeatureDataTable go from the table to getting plotted to the variablelayer on the map.

Frequenly in my test runs I have been getting the below area, obviously doing something wrong.

 

var

GPSLogProvider = new SharpMap.Data.Providers.OleDbPoint(LocalConn, "GPSLog", "ID", "dblLatitude", "dblLongitude");

GPSLogProvider.DefinitionQuery = SQLQueryDef; 

//Create Layer for Vehicles

 

var layVehicles = new SharpMap.Layers.VectorLayer("Trucks" , GPSLogProvider);

 

System.InvalidOperationException was unhandled by user code
  Message=Object is currently in use elsewhere.
  Source=System.Drawing
  StackTrace:
       at System.Drawing.Image.get_Width()
       at SharpMap.Rendering.VectorRenderer.DrawPoint(Graphics g, Point point, Image symbol, Single symbolscale, PointF offset, Single rotation, Map map) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Rendering\VectorRenderer.cs:line 466
       at SharpMap.Layers.VectorLayer.RenderGeometry(Graphics g, Map map, Geometry feature, VectorStyle style) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Layers\VectorLayer.cs:line 353
       at SharpMap.Layers.VectorLayer.Render(Graphics g, Map map) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Layers\VectorLayer.cs:line 309
       at SharpMap.Map.RenderMap(Graphics g, LayerCollectionType layerCollectionType) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Map\Map.cs:line 253
       at SharpMap.Forms.MapImage.GetMap(LayerCollection layers, LayerCollectionType layerCollectionType) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap.UI\Forms\MapImage.cs:line 264
       at SharpMap.Forms.MapImage.VariableLayersRequery(Object sender, EventArgs e) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap.UI\Forms\MapImage.cs:line 157
       at SharpMap.Layers.VariableLayerCollection.OnRequery() in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Layers\VariableLayerCollection.cs:line 97
       at SharpMap.Layers.VariableLayerCollection.TimerElapsed(Object sender, ElapsedEventArgs e) in C:\DataDrive\Projects\SharpMap\Trunk\SharpMap\Layers\VariableLayerCollection.cs:line 50
       at System.Timers.Timer.MyTimerCallback(Object state)
  InnerException:

Coordinator
Nov 3, 2010 at 12:50 PM
Edited Nov 3, 2010 at 12:52 PM

Chuck,

how many trucks do you have?

Maybe you need to increase the interval. It seems to me the layVehicles is not done with the previous query when it wants to do the next. I've had issues when i pan the map during an update cycle. I don't know if there are error handling routines in the patch I sent or not.

Hth FObermaier

Nov 3, 2010 at 1:00 PM
Only one truck.

I will increase the interval. Any suggested value?

How does the map get its plot points from the featuredata populated from the db?

Sent from my HTC Tilt™ 2, a Windows® phone from AT&T



From: FObermaier <notifications@codeplex.com>
Sent: Wednesday, November 03, 2010 7:50 AM
To: csalerno@csitgroup.com
Subject: Re: SharpMap Function [SharpMap:231724]

From: FObermaier

Chuck,

how many trucks do you have?

Maybe you need to increase the interval. It seems to me the layVehicles is not done with the previous query when it wants to do the next

Hth FObermaier

Read the full discussion online.

To add a post to this discussion, reply to this email (SharpMap@discussions.codeplex.com)

To start a new discussion for this project, email SharpMap@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Nov 3, 2010 at 2:52 PM

every interval the variablelayerscollection asks to be requeried. If the mapviewcontrol is able to cope with that request, e.g. the map is not currently being dragged, it does the variablelayercollection the favor and lets the map rerender the variable image and merges that with the static image to the mapviewcontrol.image.

I have no clue, in the sample i updated every second or so. with just one truck to render you shouldn't run into such issues. Are you doing anything else to the map when it throws the exception?

Btw.: you said in an earlier post that you had your tracking app almost ready when geoframework closed the door. GeoFramework2.0 and GPS3.0 have been ported to DotSpatial.Positioning (http://dotspatial.codeplex.com)
It is probably in an alpha stage, but maybe it serves you.

hth FObermaier

Coordinator
Nov 3, 2010 at 3:22 PM

Not that I want to discurage you to use SharpMap, but ou might also want to try Pauldendulks SharpMap based MapsUI library.

cheers FObermaier

 

Nov 3, 2010 at 3:49 PM
Thank you.

I'll look at geoframework 2.0 some more. I'm not strong at all with GIS stuff.

Chuck


Sent from my HTC Tilt™ 2, a Windows® phone from AT&T



From: FObermaier <notifications@codeplex.com>
Sent: Wednesday, November 03, 2010 10:23 AM
To: csalerno@csitgroup.com
Subject: Re: SharpMap Function [SharpMap:231724]

From: FObermaier

Not that I want to discurage you to use SharpMap, but ou might also want to try Pauldendulks SharpMap based MapsUI library.

cheers FObermaier

Read the full discussion online.

To add a post to this discussion, reply to this email (SharpMap@discussions.codeplex.com)

To start a new discussion for this project, email SharpMap@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Dec 1, 2010 at 11:27 AM

Hi there. When I try to compile the last Change Set there are some problems there.

The type or namespace name 'LayerCollectionType' could not be found (are you missing a using directive or an assembly reference?) \SharpMap\Source\SharpMap\Map\Map.cs - line: 235 - project: SharpMap.VS2008    and so on...

I can't find LayerCollectionType class ((


Coordinator
Dec 1, 2010 at 11:53 AM

I probably forgot to add it to the vs2008 project files. You can add them manually

I Will do so ASAP

cheers FObermaier

Dec 1, 2010 at 6:57 PM

Thank you for the so quick answer.

Yes, it's true. There are no problems with 2010 project.