C # Read and Write the shape projection information using the gdal/OGR Library [original]

Source: Internet
Author: User
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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.