<div>Hi </div><div>Thanks Frank :</div><div><br></div><div>In C# : </div><div><br></div><div>public static int GetWKID(OSR.SpatialReference spatialRef)</div><div> {</div><div> int wkid = -1;</div><div> if (spatialRef.IsProjected()==1)</div>
<div> {</div><div> </div><div> string PROJCS = spatialRef.GetAuthorityName("PROJCS");</div><div> if (PROJCS != null && PROJCS.Equals("EPSG"))</div>
<div> {</div><div> Int32.TryParse(spatialRef.GetAuthorityCode("PROJCS"),out wkid);</div><div> }</div><div> }</div><div> else if (spatialRef.IsGeographic() == 1)</div>
<div> {</div><div> string GEOGCS = spatialRef.GetAuthorityName("GEOGCS");</div><div> if (GEOGCS != null && GEOGCS.Equals("EPSG"))</div><div> {</div>
<div> Int32.TryParse(spatialRef.GetAuthorityCode("GEOGCS"), out wkid);</div><div> }</div><div> }</div><div><br></div><div> return wkid;</div><div> }</div>
<div><br></div><div>For the ESRI Part it should be :</div><div><div>ISpatialReferenceFactory3 spatialFact = new SpatialReferenceEnvironmentClass();</div><div>ISpatialReference lreference = null; </div><div>int wkid = GetWKID(ogrSR);</div>
<div> if (wkid != -1)</div><div> lreference = spatialFact.CreateSpatialReference(wkid);</div><div> else</div><div> {</div><div> ogrSR.MorphToESRI();</div><div> string wktSR = "";</div>
<div> ogrSR.ExportToWkt(out wktSR);</div><div> lreference = create from wkt<br></div><div> // lreference = spatialFact.CreateESRISpatialReferenceFromPRJ(wktSR);</div><div> }</div>
</div><div><br></div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2012/11/17 Frank Warmerdam <span dir="ltr"><<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Xavier,<br>
<br>
You haven't indicated your target language.<div class="im"><br>
<br>
On 12-11-17 08:22 AM, xavier lhomme wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi<br>
<br>
How to get the EPSG Code from a OSR.SpatialReference ?<br>
</blockquote>
<br></div>
In C++ you could do something like:<br>
<br>
int nPCS = -1;<br>
if( poSRS->GetAuthorityName("<u></u>PROJCS") != NULL<br>
&& EQUAL(poSRS->GetAuthorityName(<u></u>"PROJCS"),"EPSG") )<br>
{<br>
nPCS = atoi(poSRS->GetAuthorityCode("<u></u>PROJCS"));<br>
}<br>
<br>
This works for projected coordinate systems. For geographic<br>
coordinate systems you could replace PROJCS with GEOGCS.<br>
<br>
I would add that for coordinate systems without existing AUTHORITY<br>
entries with the EPSG codes it can be helpful to run the<br>
AutoIdentifyEPSG() method on the OGRSpatialReference. This will make<br>
a somewhat feeble attempt to recognise EPSG coordinate systems and<br>
attach the authority codes.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there some explample to create an ESRI ISpatialReference from a<br>
OSR.SpatialReference ?<br>
</blockquote>
<br></div>
I am not familiar with ISpatialReference, but with an OGRSpatialReference<br>
you can call morphToESRI() to switch the coordinate system definition<br>
format to match what is expected by the ArcGIS Projection Engine and<br>
then fetch the string out with ExportToWkt(). In Python this might look<br>
something like:<br>
<br>
srs = ogr.SpatialReference()<br>
srs.ImportFromEPSG(4202)<br>
srs.MorphToESRI()<br>
pe_wkt = srs.ExportToWkt()<br>
<br>
Best regards,<span class="HOEnZb"><font color="#888888"><br>
-- <br>
------------------------------<u></u>---------+--------------------<u></u>------------------<br>
I set the clouds in motion - turn up | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
light and sound - activate the windows | <a href="http://home.gdal.org/warmerda" target="_blank">http://home.gdal.org/warmerda</a><br>
and watch the world go round - Rush | Geospatial Software Developer<br>
<br>
______________________________<u></u>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/gdal-dev</a><br>
</font></span></blockquote></div><br></div>