New SharpMap User

Topics: SharpMap v2.0
Jul 8, 2009 at 9:33 AM

HI, I have just downloaded and started to have a play with SharpMap v2 and so far I like what I see.

I have already managed to put together a small applications to draw Shape files, great stuff.

One of things I will need todo is to create a set of new Providers for some other file types that are currently not included, I will happly share my work once it is complete.

The first Provider I would like to develop is one that will read a simple text file that contains a number of polyline, the format is very simple. Appart from the fact I need to be able to read these files in one of the main reasons I am look to write this provider is to try and get to know the SharpMap code.

I don't seam to be able to put my hands on any How Tos  or much documentation regarding the code, so any help or pointers that you could provide for me would be most helpful.

I have tried to copy the ShapFile provider class as a starting point, and derived my class from FeatureProviderBase, but that is about as far as I have got.

Thanks for a great project and I hope I will be able to contribute at least in a small way.

Best Regards

Andy Cheetham

 

 

 

Coordinator
Jul 8, 2009 at 10:52 AM
Edited Jul 8, 2009 at 10:54 AM

Hi Andy, just checking that you are starting with the v2 code from http://sharpmapv2.googlecode.com ...

Unfortunately documentation is a bit scarce for v2 but you would start with a provider that implemented IFeatureProvider | IFeatureProvider<TOId> | IWritableFreatureProvider<TOId>.

If you start with FeatureProviderBase you would need to implement CreateNewTable - if your datasource has no attribute data this may be as simple as:  new FeatureDataTable(GeoemtryFactory)

you would also need to override GetSchemaTable - this should return a DataTable where each row represents meta data about a column in the datasource - if you have no attribute columns you can return an empty schema table from :

DataTable schema = ProviderSchemaHelper.CreateSchemaTable();

overriding the InternalExecuteFeatureQuery methods you would read from your source file , tokenizing into chunks perhaps on linebreaks or some other control character (You may choose to do this using a seperate 'reader' class).
Parse the chunks into Geometries (if the data is stored as wkt this is as simple as this.GeometryFactory.WktReader.Read(data)),
And then evaluate the resulting geometry against the query expression argument to check whether it matches and should be returned or skipped over.
Matching geometries are then returned as an IFeatureDataRecord within an IFeatureDataReader you can use the ShapeFileDataReader or SpatialDbFeatureDataReader as an example. (A shortcut here would be to add rows to a new FeatureDataTable and then return new FeatureDataTableReader(featureDataTable) )

hth jd

Jul 8, 2009 at 12:53 PM
Edited Jul 8, 2009 at 1:03 PM

Hi John

Thanks for the quick response.
Yes I started with the code from the googlecode.com.

My datasource does not have any attribute data, as it is just a simple text file that only contains the coordinates for the lines.

Therefore I have followed your advice with regards to the CreateNewTable function and GetSchemaTable.

I have overridden the InternalExecuteFeatureQuery function and have tried to implement the short cut you suggested and return a new FeatureDataTableReader .

However it looks like the FeatureDataTableReader class is throwing an exception because the following function has not been implemented.

public IEnumerator<IFeatureDataRecord> GetEnumerator()

Is this because I need to override  this in a  derived class or more simply because the v2 has not been completed yet?

I very much appreciate your help.

Best Regards
Andy

johndiss wrote:

From: johndiss

Hi Andy, just checking that you are starting with the v2 code from http://sharpmapv2.googlecode.com ...

Unfortunately documentation is a bit scarce for v2 but you would start with a provider that implemented IFeatureProvider | IFeatureProvider<TOId> | IWritableFreatureProvider<TOId>.

If you start with FeatureProviderBase you would need to implement CreateNewTable - if your datasource has no attribute data this may be as simple as:  new FeatureDataTable(GeoemtryFactory)

you would also need to override GetSchemaTable - this should return a DataTable where each row represents meta data about a column in the datasource - if you have no attribute columns you can return an empty schema table from :

DataTable schema = ProviderSchemaHelper.CreateSchemaTable();

overriding the InternalExecuteFeatureQuery methods you would read from your source file , tokenizing into chunks perhaps on linebreaks or some other control character (You may choose to do this using a seperate 'reader' class).
Parse the chunks into Geometries (if the data is stored as wkt this is as simple as this.GeometryFactory.WktReader.Read(data)),
And then evaluate the resulting geometry against the query expression argument to check whether it matches and should be returned or skipped over.
Matching geometries are then returned as an IFeatureDataRecord within an IFeatureDataReader 
you can use the ShapeFileDataReader or SpatialDbFeatureDataReader as an example. (A shortcut here would be to add rows to a new FeatureDataTable and then return new FeatureDataTableReader(featureDataTable) )

 

hth jd

 

 

 

-- 

Andrew Cheetham

Coordinator
Jul 8, 2009 at 1:04 PM

Sorry, I should have checked the state of that class.. It hasn't been implemented fully.. but may make for a good 'learning' implementation -  the FeatureDataRow implements IFeatureDataRecord so you can just relay calls to the current row leaving just tracking of current index and row .. SVN patches gladly recieved ;) cheers jd

Jul 8, 2009 at 3:45 PM
Edited Jul 9, 2009 at 7:16 AM

Hi John,

I have populated the FeatureDataTableReader class and created a svn Patch file, where would you like me to send it?

Cheers
Andy

johndiss wrote:

From: johndiss

Sorry, I should have checked the state of that class.. It hasn't been implemented fully.. but may make for a good 'learning' implementation -  the FeatureDataRow implements IFeatureDataRecord so you can just relay calls to the current row leaving just tracking of current index and row .. SVN patches gladly recieved ;) cheers jd

 

--
Coordinator
Jul 8, 2009 at 4:02 PM

Hi Andy, thanks :) please post it to http://sharpmap.codeplex.com/SourceControl/PatchList.aspx - that way other people can benefit even if it takes a little while to make it into the trunk.. cheers jd

Jul 8, 2009 at 6:14 PM
Edited Jul 9, 2009 at 7:15 AM

Hi John,
I have submitted the patch to the PatchList, its my first attempt to contribute to an open source project, so I'm prepared accept any feedback!!

;-)

Cheers
Andy

johndiss wrote:

From: johndiss

Hi Andy, thanks :) please post it to http://sharpmap.codeplex.com/SourceControl/PatchList.aspx - that way other people can benefit even if it takes a little while to make it into the trunk.. cheers jd

 

-- 

Jul 9, 2009 at 7:38 AM

Hi John

I think I have missed something when I have implimented my Data Provider. I first thought there was a problem because is seamed to be taking a while to draw the contents of the files I was loading.

I think I have tracked down the cause of the bottle neck:

When the layer is being drawn in either phase Selected or highlighted (winthin the MapPresenter2D) the layer is returning what appears to be all the features in the layer. But I have not, knowingly at least, selected or highlighted any features.

I'm therefore thinking that all the features are being drawn 3 times and hence the drawing is taking longer than expected.

I'm not sure why or how this is happening any ideas?

I notice this is not happening when a shape file is selected.

I even went ahead and created a 'reader' class for my provider, but this did not make an difference.

I'm not sure which bit of code of mine would help you solve the probem, but I will share anything with you that will help.

 

Cheers

Andy 

 

 

Coordinator
Jul 9, 2009 at 9:44 AM

Hi Andy, there are a few known issues with the control - in fact it there are quite a lot of changes to the rendering pipeline being planned.

The FeatureLayer reads data from the data provider into a FeatureDataTable which it then uses to read from for rendering - this then has views for Selected and Highlighted. There is an issue with the performance of the indexing of this FeatureDataTable -  you can switch it off by calling featureLayer.Features.IsSpatiallyIndexed = false;

WRT your issue - looking @ line 1040 in MapPresenter2D.cs all the features matching the query are selected during the Normal render phase (I am not sure if this behaviour is correct - I will look into it when I get a chance)

hth jd

 

Coordinator
Jul 9, 2009 at 9:54 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.