[gdal-dev] Create a ISpatialReference from an SpatialReference

xavier lhomme lhomme.xavier at gmail.com
Sun Nov 18 02:00:19 PST 2012


Hi
Thanks Frank :

In C# :

public static int GetWKID(OSR.SpatialReference spatialRef)
        {
            int wkid = -1;
            if (spatialRef.IsProjected()==1)
            {

                string PROJCS = spatialRef.GetAuthorityName("PROJCS");
                if (PROJCS != null && PROJCS.Equals("EPSG"))
                {

 Int32.TryParse(spatialRef.GetAuthorityCode("PROJCS"),out wkid);
                }
            }
            else if (spatialRef.IsGeographic() == 1)
            {
                string GEOGCS = spatialRef.GetAuthorityName("GEOGCS");
                if (GEOGCS != null && GEOGCS.Equals("EPSG"))
                {
                    Int32.TryParse(spatialRef.GetAuthorityCode("GEOGCS"),
out wkid);
                }
            }

            return wkid;
        }

For the ESRI Part it should be :
ISpatialReferenceFactory3 spatialFact = new
SpatialReferenceEnvironmentClass();
ISpatialReference lreference = null;
int wkid = GetWKID(ogrSR);
 if (wkid != -1)
    lreference = spatialFact.CreateSpatialReference(wkid);
 else
    {
                ogrSR.MorphToESRI();
                string wktSR = "";
                ogrSR.ExportToWkt(out wktSR);
                lreference = create from wkt
               // lreference =
spatialFact.CreateESRISpatialReferenceFromPRJ(wktSR);
   }




2012/11/17 Frank Warmerdam <warmerdam at pobox.com>

> Xavier,
>
> You haven't indicated your target language.
>
>
> On 12-11-17 08:22 AM, xavier lhomme wrote:
>
>> Hi
>>
>>   How to get the EPSG Code from  a OSR.SpatialReference ?
>>
>
> In C++ you could do something like:
>
>     int nPCS = -1;
>     if( poSRS->GetAuthorityName("**PROJCS") != NULL
>         && EQUAL(poSRS->GetAuthorityName(**"PROJCS"),"EPSG") )
>     {
>         nPCS = atoi(poSRS->GetAuthorityCode("**PROJCS"));
>     }
>
> This works for projected coordinate systems.  For geographic
> coordinate systems you could replace PROJCS with GEOGCS.
>
> I would add that for coordinate systems without existing AUTHORITY
> entries with the EPSG codes it can be helpful to run the
> AutoIdentifyEPSG() method on the OGRSpatialReference.  This will make
> a somewhat feeble attempt to recognise EPSG coordinate systems and
> attach the authority codes.
>
>
>    Is there some explample to create an ESRI ISpatialReference  from a
>> OSR.SpatialReference ?
>>
>
> I am not familiar with ISpatialReference, but with an OGRSpatialReference
> you can call morphToESRI() to switch the coordinate system definition
> format to match what is expected by the ArcGIS Projection Engine and
> then fetch the string out with ExportToWkt().  In Python this might look
> something like:
>
>     srs = ogr.SpatialReference()
>     srs.ImportFromEPSG(4202)
>     srs.MorphToESRI()
>     pe_wkt = srs.ExportToWkt()
>
> Best regards,
> --
> ------------------------------**---------+--------------------**
> ------------------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://home.gdal.org/warmerda
> and watch the world go round - Rush    | Geospatial Software Developer
>
> ______________________________**_________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/**mailman/listinfo/gdal-dev<http://lists.osgeo.org/mailman/listinfo/gdal-dev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20121118/d99e26be/attachment.html>


More information about the gdal-dev mailing list