demo of sharpmap and writing shapefiles with nts

903 views
Skip to first unread message

agelospanagiotakis

unread,
Mar 14, 2009, 2:18:28 PM3/14/09
to NetTopologySuite
i am using sharpmap v.0.9 - (no write support) and i ve been trying to
find a way to create a new shapefile by using nts
I loading a shapefile in sharpmap and displaying fields in a
datagridview.
I am adding a new column and then want to save the new dataset using
nts.
Please download and advice : http://147.102.85.132/sharpmapV0.9-writeWithNTS.rar
I am using vb.net but a code sample in c# won't be a problem.
I am sure that you will have a solution to this one.
I am also trying to figure out a way to determine column ValueType so
that i can add a DbaseFileHeader using AddColumn.

Thank you in advance for your excelent job,
Agelos

Diego Guidi

unread,
Mar 15, 2009, 6:03:56 AM3/15/09
to NetTopologySuite
Use ShapefileDataWriter.GetHeader(...) to create header, and in
general take a look at
http://code.google.com/p/nettopologysuite/source/browse/trunk/NetTopologySuite.Samples.Console/SimpleTests/Attributes/AttributesTest.cs

On Mar 14, 7:18 pm, agelospanagiotakis <agelospanagiota...@gmail.com>
wrote:

mindspit

unread,
Mar 15, 2009, 10:44:45 AM3/15/09
to NetTopologySuite
Well i do that, have you seen the uploaded file ?
Please take a look.
Thanks,
Agelos


On Mar 15, 12:03 pm, Diego Guidi <diegogu...@gmail.com> wrote:
> Use ShapefileDataWriter.GetHeader(...) to create header, and in
> general take a look athttp://code.google.com/p/nettopologysuite/source/browse/trunk/NetTopo...

Diego Guidi

unread,
Mar 16, 2009, 3:53:49 AM3/16/09
to NetTopologySuite
> Please take a look.
Looks like you create shapefile header pefore create features, so
numrecords is set to 0.
Make sure that call static method CreateHeader after yo'uve created
the list of features.

mindspit

unread,
Mar 16, 2009, 5:05:00 AM3/16/09
to NetTopologySuite
You see i can't understand .... witch of the following should i do.
a)
i should create a new header like this
Dim myHeader As New GisSharpBlog.NetTopologySuite.IO.DbaseFileHeader
and then add columns in it
myHeader.AddColumn(clm.Name, "C", 20, 0)
or
b)
should i create it like this :
Dim shapeDataWriter As New
GisSharpBlog.NetTopologySuite.IO.ShapefileDataWriter(savePath,
GSfactory)
then do something like
shapeDataWriter.Header =
GisSharpBlog.NetTopologySuite.IO.ShapefileDataWriter.GetHeader(ntsFeats
(0), ntsFeats.Length)
to automaticaly get the header
and finaly write the file using
shapeDataWriter.Write(ntsFeats)
______________________________________________________________________________________________________________
this is not clear to me.
Thanks for your response.
P.S.: are you italian ?

Diego Guidi

unread,
Mar 16, 2009, 5:36:17 AM3/16/09
to NetTopologySuite
> Dim shapeDataWriter As New
> GisSharpBlog.NetTopologySuite.IO.ShapefileDataWriter(savePath,
> GSfactory)
> then do something like
> shapeDataWriter.Header =
> GisSharpBlog.NetTopologySuite.IO.ShapefileDataWriter.GetHeader(ntsFeats
> (0), ntsFeats.Length)
> to automaticaly get the header
> and finaly write the file using
> shapeDataWriter.Write(ntsFeats)

exactly

mindspit

unread,
Mar 16, 2009, 12:05:21 PM3/16/09
to NetTopologySuite
Dear Diego,

and what about if i want to change this so called header?
can i add one more new columns by using AddColumn or change the order
of appearance?
I noticed that this seems to be done automatticly when i add a new
attributre with
ntsAttributes.AddAttribute(name, value)
This point is a little bit confusing. Where should i state the
properties of this column? ( Name, DbaseType, Length, DecimalCount )
Anyway the generated file doen't work and i wonder why that happens.
Is there a working demo out of this functionality out there?
I am using an older version of the library .... maybe thats the issue?
You see i am using it with v.0.9 of sharpmap
Thanks again for all your help
...
Agelos

Diego Guidi

unread,
Mar 16, 2009, 12:23:31 PM3/16/09
to NetTopologySuite
the best way to do this is to regenerate anytime a new shapefile :(
features and shapefile support is a very poor API in NTS (that is
mainly for topology) and is poorly tested.
maybe you could try to use sharpmap buildin capabilities

mindspit

unread,
Mar 17, 2009, 7:49:17 AM3/17/09
to NetTopologySuite
unfortunatelly this is not possible with sharpmap v.0.9.

I will try to
a)create a new file using nts ,
b)save it in a new file and then
c) remove the layer from my map,
d) overwrite the old shp file with the new one created using nts
e) and finally add the layer back to the map!
Unfortunatelly it won't be wise to do this everytime i change a value
in the tab data.
:(

Thanks again.
Keep up the good work to enable us do more!

Diego Guidi

unread,
Mar 17, 2009, 7:55:42 AM3/17/09
to nettopol...@googlegroups.com
> Unfortunatelly it won't be wise to do this everytime i change a value in the tab data.
:(
> Thanks again.
> Keep up the good work to enable us do more!
Thanks :)
I try to do my best!
Reply all
Reply to author
Forward
0 new messages