Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Anyone know of a free OpenSource .NET library i could use to convert KML to WKT?

I know i can use openlayers and there are many JavaScript possibilities, but i need to do this on the back-end.

share|improve this question
    
SharpMap is an easy-to-use mapping library for use in web and desktop applications. sharpgis.net/category/SharpMap.aspx –  user3120 Nov 2 '11 at 2:13

3 Answers 3

How about using GDAL's OGR .NET bindings?

http://bjarte.com/post/gdal-in-csharp

and its KML driver through libkml http://www.gdal.org/ogr/drv_libkml.html

Alternatively, you could use libkml directly.

share|improve this answer
    
I don't see any KML readers in the GDAL gone wild project. Am i missing something? –  CaptDragon Oct 31 '11 at 19:10
    
Ugh, you are right. The libkml drivers came this year and those are from last year. Can you check if the OSGeo4W binaries have the libkml dll in it? –  Ragi Yaser Burhum Oct 31 '11 at 20:10
    
Nothing from what i can see. –  CaptDragon Oct 31 '11 at 20:35

Your other option is to use the NetTopologySuite which is a port from the Java version, it supports WKT Reading/Writing.

We've then taken the Kml xsd, using the provided ms tools converted it to classes which the xml serialiser understands and then walked the tree converting the nodes we cared about into NTS IGeometry that the rest of our system used.

share|improve this answer
    
I'll try this and let you know. –  CaptDragon Oct 31 '11 at 20:35
    
I've created the classes from xsd now...Do you know which dlls int he NTS have the WKT read/write capabilities? –  CaptDragon Nov 1 '11 at 13:43
    
I use GisSharpBlog.NetTopologySuite.IO WKTWriter/WKTReader –  Thomas James Nov 2 '11 at 5:43
    
How did you go with it? –  Thomas James Nov 4 '11 at 2:29
    
Actually, I'm using something very unconventional, but it works like a charm and it's very easy, and it's what i need. I'll post an update soon. Basically i'm having my PostGIS database do it for me. –  CaptDragon Nov 4 '11 at 16:39
up vote 1 down vote accepted

Since i'm using post GIS, I ended up having it do it for me:

If i need two KML feature's converted, i'll send it a select like the following:

SELECT  ST_AsText(ST_GeomFromKML('<Polygon >
  <outerBoundaryIs>
    <LinearRing>
      <coordinates>
                    120.801170655354,14.632489189195,0
                    120.782956111463,14.5427894930054,0
                    120.76474480255,14.4530886861418,0
                    120.925219414103,14.4220920136416,0
                    120.943496765891,14.5117984961193,0
                    120.961777812394,14.6015038368517,0
                    120.801170655354,14.632489189195,0
                  </coordinates>
    </LinearRing>
  </outerBoundaryIs>
</Polygon>')), ST_AsText(ST_GeomFromKML('<Polygon >
  <outerBoundaryIs>
    <LinearRing>
      <coordinates>
                    121.087312420981,14.6013782055702,0
                    121.071223131928,14.5142178677531,0
                    121.244070778376,14.4838207663532,0
                    121.260233278214,14.571006143522,0
                    121.087312420981,14.6013782055702,0
                  </coordinates>
    </LinearRing>
  </outerBoundaryIs>
</Polygon>'))

Result:

"POLYGON((120.801170655354 14.632489189195,120.782956111463 14.5427894930054,120.76474480255 14.4530886861418,120.925219414103 14.4220920136416,120.943496765891 14.5117984961193,120.961777812394 14.6015038368517,120.801170655354 14.632489189195))";"POLYGON((121.087312420981 14.6013782055702,121.071223131928 14.5142178677531,121.244070778376 14.4838207663532,121.260233278214 14.571006143522,121.087312420981 14.6013782055702))"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.