Tuesday, 15 February 2011

geospatial - How to export WKT from a Shapefile in c#? -



geospatial - How to export WKT from a Shapefile in c#? -

i have shapefile contains several one thousand polygons.

i need read file in c# , output list of wkt formatted strings.

i looked @ dotspatial , "catfood" esri shapefile reader. can either load shapefile fine, cannot figure out how export wkt.

in dotspatial, examples find utilize wktwriter takes geometry. couldn't figure out how geometry shape.

is there library that's more appropriate this?

update

thanks mdm20's answer, able write following:

using (var fs = featureset.open(path)) { var author = new wktwriter(); var numrows = fs.numrows(); (int = 0; < numrows; i++) { var shape = fs.getshape(i, true); var geometry = shape.togeometry(); var wkt = writer.write((geometry) geometry); debug.writeline(wkt); } }

the reason missed because next this sample, uses fs.shapeindices instead of fs.getshape(). returns not shape, shaperange, couldn't convert geometry.

new questions

should setting fs.indexmode = true? why or why not? doesn't seem have performance or results impact. fs.getshape() takes boolean called getattributes. have attributes on shapes, , seem come through whether set true or false. again, there no noticeable performance impact either way. expected? by getting them in way, wkt represent actual values stored in shapefile? or transformed in way? taking default settings dotspatial account, , should concerned changing them? the shapefile importing world timezone map. contain .prj file. dotspatial take account, , if not - need extra?

many thanks!

in dotspatial, shape class has togeometry method.

/// <summary> /// converts shape geometry using default factory. /// </summary> /// <returns>the geometry version of shape.</returns> public igeometry togeometry() { homecoming togeometry(geometry.defaultfactory); }

edit

i've used dotspatial stuff projections, can't help much.

1-2: not sure. code open source if want , see do

3: wkt human readable text representation of geometry. assume it's same value file, don't know. again.. check out dotspatial source code

4: prj file tells projection geometry in. depending on want it, might have re-project it. things bing maps , google earth utilize mercator projection, instance. dotspatial projections library , makes easy transform geometry 1 projection another.

i've done quite bit of work shapefiles.. allow me know if have more questions.

c# geospatial shapefile wkt

No comments:

Post a Comment