Today, I spent a little time reading and writing the projection information in shape in OGR in C.
For information about the read/write vectors and attributes, see the previous article. C # Use the gdal/OGR library to create and write a shape file. The test passes the [original]
the specific process is
// project experiment area
osgeo. OSR. spatialreference SS;
SS = orglayer. getspatialref (); // The orglayer is osgeo. OGR. layer instances
string PPSS;
SS. exporttowkt (Out PPSS); // output the shape projection information of the read file to the formatted string PPSS
MessageBox. show (PPSS);
very simple.
for example, the output encoding string is
geogcs ["gcs_north_american_1927", datum ["north_american_datum_1927", spheroid ["clarke_1866", 6378206.4, 294.9786982], primem ["Greenwich", 0], Unit ["degree ", 0.0174532925199433]
This string is the standard WKT string in OGR.
the process of writing projection information to the new shape is also relatively simple..
string strwkt = "geogcs [\" gcs_north_american_1927 \ ", datum [\" north_american_datum_1927 \ ", spheroid [\" clarke_1866 \ ", 6378206.4, 294.9786982], primem [\ "Greenwich \", 0], Unit [\ "degree \", 0.0174532925199433] ";
note that the double quotation marks in the string are \"
osgeo. OSR. spatialreference SRS = new osgeo. OSR. spatialreference (strwkt);
// then, in the layer creation function, the second parameter is // osgeo. OSR. spatialreference
polayer = pods. createlayer ("layername1", SRS, osgeo. OGR. wkbgeometrytype. wkbpoint, null);