Converting between Esri Geometry and WKT using ArcObjects?(转载)
|
It seems like there is no means of converting an ArcObjects geometry to the Well-Known Text representation (and vice versa) in ArcGIS ArcObjects API. The only thing I was able to find is conversion to WKB (the IWkb interface). Is there a way to perform conversion between geometry objects and WKT or do I have to implement it myself? I primarily aim for .NET implementation without much external dependencies. |
|||
|
add a comment
|
|
In the past, I've used Sharpmap's converter, but I had to get to WKB first. I don't know if it is the best option now.
I also don't know of where the current SharpMap repository is, but I did find a reference of the class here: http://www.google.com/codesearch/p?hl=en#FDsea6rqN6I/trunk/Thirdparty/SharpMap/SharpMap/Converters/WellKnownText/GeometryToWKT.cs&q=converter%20package:http://fdotoolbox%5C.googlecode%5C.com&sa=N&cd=6&ct=rc At the time, I think I was using SharpMap from Codeplex. I forgot about ZigGIS. You might be able to build on that code--this link is the older ziggis. It's the aoPolygonToWkt,aoPointToWkt,aoPolylineToWkt methods that I'm thinking would work:http://www.google.com/codesearch/p?hl=en#YxxleBCXM18/ZigGis/helpers.cs&q=WKT%20package:http://ziggis%5C.googlecode%5C.com&sa=N&cd=1&ct=rc&l=138 |
|||||||||
|
|
Using the IWkb interface does a nice job at converting between an IGeometry and WKB. From a WKB you can use the Microsoft.SqlServer.Types library to convert a WKB to SqlGeometry then back to WKT.
At this point you have the WKB stored in wkb_bytes. If you want to go the next step to SqlGeometry then to WKT:
|
|||||||||
|
|
You might try referencing the Microsoft.SqlServer.Types assembly (which I believe is included with the free Sql Server Express edition), then use STGeomFromWKB static method to create a microsoft geometry, which could then be converted into WKT using STAsText. Also note that while Microsoft catches a lot of flak about being proprietary, they do offer source code to a lot of useful functions in their SqlServer Spatial Tools at codeplex. So if the SqlServerTypes is too much external dependency for you you might be able to find source code that does this. |
|||||
|
|
NTS can "speak" WKT, and has readers and writers for both WKB and WKT. So if you have WKB, NTS can read that and write to WKT. However, you could also create NTS objects by using the attributes of an ArcObjects geometry and then output as WKT. For one of our ArcObjects projects we created utility methods for NTS to move geometry around (mostly to take advantage of the alternate projection methods NTS offers). |
|||||
|
|
The DNRGPS open source project (licensing here) has extension methods for converting between The license looks pretty permissive so I put my standalone version (does not use Update: I've made a few improvements to my version to support applying spatial references for the output geometry objects and using a integer coordinate friendly default spatial reference (Plate Carree) if none is specified. |
|||||
|
|
Check out GeometryBridge, it might be able to help you.http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000039n000000 |
|||||||||||||
|
转自:http://stackoverflow.com/questions/14992412/how-to-export-wkt-from-a-shapefile-in-c
浙公网安备 33010602011771号