<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Convert ISpatialReference to WKT in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127216#M20419</link>
    <description>&lt;P&gt;There's also the &lt;A href="https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#ISpatialReferenceFactory_ExportESRISpatialReferenceToPRJFile.htm" target="_blank" rel="noopener"&gt;ISpatialReferenceFactory.ExportESRISpatialReferenceToPRJFile&lt;/A&gt; Method&lt;/P&gt;</description>
    <pubDate>Fri, 17 Dec 2021 16:48:32 GMT</pubDate>
    <dc:creator>KirkKuykendall1</dc:creator>
    <dc:date>2021-12-17T16:48:32Z</dc:date>
    <item>
      <title>Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1126896#M20416</link>
      <description>&lt;P&gt;ArcMap 10.8.1 using .NET ArcObjects&lt;/P&gt;&lt;P&gt;I have a geometry with a spatial reference. How do I get its projection WKT? I've been looking for hours and can't seem to find a simple way to do this.&lt;/P&gt;&lt;P&gt;Dim pGeom As IGeometry = CreateGeometry()&lt;/P&gt;&lt;P&gt;Dim wkt as String =&amp;nbsp;pGeom.SpatialReference.ToWKT '&amp;lt;=== What API do I use for this conversion?&lt;/P&gt;&lt;P&gt;The output should be something like:&lt;/P&gt;&lt;P&gt;PROJCS["World_Azimuthal_Equidistant",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Azimuthal_Equidistant"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-86.02400831252139],PARAMETER["Latitude_Of_Origin",41.70912056625856],UNIT["Meter",1.0]]&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 20:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1126896#M20416</guid>
      <dc:creator>AbelPerez</dc:creator>
      <dc:date>2021-12-16T20:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127091#M20417</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You can serialize ISpatialReference object to xml ant then read wkt from it. Code for serialization:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        private static string GetSpatialReferenceAsXmlString(ISpatialReference spatialReference)
        {
            if (spatialReference == null) throw new ArgumentNullException("spatialReference");

            var xmlStream = new XMLStreamClass();
            var xmlWriter = new XMLWriterClass();
            var xmlSerializer = new XMLSerializerClass();

            xmlWriter.WriteTo(xmlStream);
            xmlSerializer.WriteObject(xmlWriter, null, null, string.Empty, string.Empty, spatialReference);

            return xmlStream.SaveToString();
        }&lt;/LI-CODE&gt;&lt;P&gt;You will get xml like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;ProjectedCoordinateSystem xsi:type='typens:ProjectedCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.8'&amp;gt;
&amp;lt;WKT&amp;gt;PROJCS[&amp;amp;quot;LKS_1994_Transverse_Mercator&amp;amp;quot;,GEOGCS[&amp;amp;quot;GCS_LKS_1994&amp;amp;quot;,DATUM[&amp;amp;quot;D_Lithuania_1994&amp;amp;quot;,SPHEROID[&amp;amp;quot;GRS_1980&amp;amp;quot;,6378137.0,298.257222101]],PRIMEM[&amp;amp;quot;Greenwich&amp;amp;quot;,0.0],UNIT[&amp;amp;quot;Degree&amp;amp;quot;,0.0174532925199433]],PROJECTION[&amp;amp;quot;Transverse_Mercator&amp;amp;quot;],PARAMETER[&amp;amp;quot;False_Easting&amp;amp;quot;,500000.0],PARAMETER[&amp;amp;quot;False_Northing&amp;amp;quot;,0.0],PARAMETER[&amp;amp;quot;Central_Meridian&amp;amp;quot;,24.0],PARAMETER[&amp;amp;quot;Scale_Factor&amp;amp;quot;,0.9998],PARAMETER[&amp;amp;quot;Latitude_Of_Origin&amp;amp;quot;,0.0],UNIT[&amp;amp;quot;Meter&amp;amp;quot;,1.0]]&amp;lt;/WKT&amp;gt;
&amp;lt;XOrigin&amp;gt;-22523120044.116333&amp;lt;/XOrigin&amp;gt;
&amp;lt;YOrigin&amp;gt;-22527998119.405388&amp;lt;/YOrigin&amp;gt;
&amp;lt;XYScale&amp;gt;18181.818166159173&amp;lt;/XYScale&amp;gt;
&amp;lt;ZOrigin&amp;gt;-100000&amp;lt;/ZOrigin&amp;gt;
&amp;lt;ZScale&amp;gt;10000&amp;lt;/ZScale&amp;gt;
&amp;lt;MOrigin&amp;gt;-100000&amp;lt;/MOrigin&amp;gt;
&amp;lt;MScale&amp;gt;10000&amp;lt;/MScale&amp;gt;
&amp;lt;XYTolerance&amp;gt;0.001&amp;lt;/XYTolerance&amp;gt;
&amp;lt;ZTolerance&amp;gt;0.001&amp;lt;/ZTolerance&amp;gt;
&amp;lt;MTolerance&amp;gt;0.001&amp;lt;/MTolerance&amp;gt;
&amp;lt;HighPrecision&amp;gt;true&amp;lt;/HighPrecision&amp;gt;
&amp;lt;/ProjectedCoordinateSystem&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Then read WKT node from it&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 09:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127091#M20417</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2021-12-17T09:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127157#M20418</link>
      <description>&lt;P&gt;Wow, I didnt know you could do that. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 15:05:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127157#M20418</guid>
      <dc:creator>AbelPerez</dc:creator>
      <dc:date>2021-12-17T15:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127216#M20419</link>
      <description>&lt;P&gt;There's also the &lt;A href="https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#ISpatialReferenceFactory_ExportESRISpatialReferenceToPRJFile.htm" target="_blank" rel="noopener"&gt;ISpatialReferenceFactory.ExportESRISpatialReferenceToPRJFile&lt;/A&gt; Method&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 16:48:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127216#M20419</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-12-17T16:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127220#M20420</link>
      <description>&lt;P&gt;I like that one too except you have to write it to disk first.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 16:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127220#M20420</guid>
      <dc:creator>AbelPerez</dc:creator>
      <dc:date>2021-12-17T16:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISpatialReference to WKT</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127284#M20421</link>
      <description>&lt;P&gt;As a final edit I took &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp;code and made it an extension. Note I use full namespaces so as not to clash with the MS XML functions.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;    &amp;lt;Extension()&amp;gt;
    Function SerializeEsri(Of T As Class)(ByVal value As T) As XDocument
        Dim sr As New ESRI.ArcGIS.esriSystem.XMLStream
        Dim ir As ESRI.ArcGIS.esriSystem.IStream = CType(sr, ESRI.ArcGIS.esriSystem.IStream)
        Dim wr As New ESRI.ArcGIS.esriSystem.XMLWriter
        Dim ser As New ESRI.ArcGIS.esriSystem.XMLSerializer

        wr.WriteTo(ir)
        ser.WriteObject(wr, Nothing, Nothing, String.Empty, String.Empty, value)

        Dim xdoc As XDocument = XDocument.Parse(sr.SaveToString)
        Return xdoc
    End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Usage:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;    Private Function GetSpatialReferenceAsWkt(pSpatRef As ISpatialReference) As String
        If pSpatRef Is Nothing Then Return Nothing

        Dim xdoc As XDocument = pSpatRef.SerializeEsri
        Dim xelem As XElement = xdoc.Root.Element("WKT")
        Return xelem.Value
    End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 19:20:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/convert-ispatialreference-to-wkt/m-p/1127284#M20421</guid>
      <dc:creator>AbelPerez</dc:creator>
      <dc:date>2021-12-17T19:20:13Z</dc:date>
    </item>
  </channel>
</rss>

