[gdal-dev] OGR_L_SetSpatialRef

Even Rouault even.rouault at mines-paris.org
Fri Apr 8 08:02:19 EDT 2011


Selon Radim Blazek <radim.blazek at gmail.com>:

Radim,

there's no API in OGR to alter the SRS of an existing layer.

However in the particular case of a shapefile, you just need to generate the
.prj file. You can do that quite easily with the OSR API. See
http://gdal.org/ogr/ogr__srs__api_8h.html

Basically, something like :

OGRSpatialReferenceH hSRS = OSRNewSpatialReference ( NULL );
OSRImportFromXXXXX(hSRS, YYYYYY);
OSRMorphToESRI(hSRS); /* this is the important stuff for shapefile .prj */
char* pszOutWkt = NULL;
OSRExportToWkt(hSRS, &pszOutWkt);
OSRDestroySpatialReference(hSRS);
fprintf(fp, "%s", pszOutWkt);
CPLFree(pszOutWkt);

> Hi,
> is there a way to assign a CRS to an existing OGR layer.
> I would like to open for example a shapefile without .prj in write
> mode, set a CRS and save it with .prj without creating a new layer.
>
> Radim
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>




More information about the gdal-dev mailing list