Gdal comprehensive sorting-1: Overview

Source: Internet
Author: User
Document directory
  • 1) OGR Architecture
  • 2) OGR geometry model
  • 3) ogr api usage example

On the Internet, I can see that this article is fully written, and it is in Chinese. I just turned around and learned it.
Some of the content is repeated, but it does not affect. Very good information.

Mainly from http://blog.csdn.net/liminlu0314? Viewmode = Contents

1. Introduction 1. gdal

In short, gdal is a database that operates on various grid geographic data formats. Including reading, writing, converting, and processing various raster data formats (some specific formats are not supported for some operations, such as writing ). It uses a single abstract data model to support most raster data (GIS's ability to abstract raster, vector, and 3D data models is amazing ). Of course, in addition to raster operations, this library also includes another famous library OGR that operates vector data (OGR this library also introduces ), in this way, the Library has the ability to operate on the grid and vector data at the same time.

The most important thing is that this library is cross-platform and open-source! Today, this database supports a wide range of data formats, including almost all types of data formats to be processed by GIS and RS. At the end of its home page, the software list that uses it as the underlying data processing not only includes grass, quantum GIS (qgis), but also Google Earth.

It is necessary to learn this database. This library can be used in C/C ++/Python/Ruby/Vb/Java/C # (this is not fully supported at the moment), and both are used in the same way.

 

Gdal (Geospatial Data Conversion action Library) is an open source grid space data conversion library under the X/MIT license protocol. It uses the abstract data model to express the Supported file formats. It also has a series of command line tools for data conversion and processing.

 

2. OGR

OGR is a branch of the gdal project. Its function is similar to gdal, but it provides support for vector data. Many famous GIS products use gdal/OGR libraries, including arggis 9.2 of ESRI, Google Earth, and cross-platform grass GIS systems.

OGR provides read and write support for vector data format, it supports file formats include: ESRI shapefiles, S-57, SDTS, postgis, Oracle Spatial, MapInfo mid/MIF, MapInfo tab.

1) OGR Architecture

OGR includes the following parts:

Geometry: Class geometry (including ogrgeometry and other classes) encapsulates the Vector Data Model of OpenGIS, and provides some geometric operations, WKB (well knows binary) and WKT (well known text) format conversion and spatial reference system (projection ).

Spatial Reference: Class ogrspatialreference encapsulates the definition of projection and datum.

Feature: Class ogrfeature encapsulates a complete feature definition. A complete feature includes a series of attributes of a geometry and geometry.

Feature Definition: Class ogrfeaturedefn contains the attributes, types, names, and default space Reference Systems of feature. An ogrfeaturedefn Object usually corresponds to a layer.

Layer: Class ogrlayer is an abstract base class that represents a layer of elements (feature) in the data source class ogrdatasource ).

Data source: Class ogrdatasource is an abstract base class that represents a file or database containing an ogrlayer object.

Drivers: The ogrsfdriver class corresponds to each supported Vector file format. Class ogrsfdriver is registered and managed by class ogrsfdriverregistrar.

 

2) OGR geometry model

 

The geometry model of OGR is built on the Simple Element Data Model of OpenGIS. As shown in:

 

 

Figure-geometry model diagram of OGR

 

The diagram of the Simple Element Data Model of OpenGIS is as follows:

 

Figure-Simple Element Data Model of OpenGIS

 

From the comparison of the above two figures, we can clearly see that the OGR geometry model strictly complies with the simple element data standards of OpenGIS. The geometry model of OGR is not only consistent with the simple element data model of OpenGIS in the inheritance system, but also close to it in the function interface. The basic method for obtaining geometry object information is as follows: dimension () geometrytype (), SRID (), envelope (), astext (), and boundary () wait until the method used to determine the unknown spatial relationship is equals (anothergeometry: geometry), disjoint (anothergeometry: geometry), intersects (anothergeometry: geometry), touches (anothergeometry: geometry) and so on are all in line with their standards.

3) ogr api usage example

The following C ++ sample code shows how to use OGR APIs to read vector data.

 

# Include "ogrsf_frmts.h" int main () {// register all file formats to drive ogrregisterall (); // open point. SHP file ogrdatasource * pods = ogrsfdriverregistrar: open ("point. SHP ", false); // get the point layer ogrlayer * polayer = pods-> getlayerbyname (" point "); ogrfeature * pofeature; // reset the layer, make sure to read data from the beginning of the layer-> resetreading (); While (pofeature = polayer-> getnextfeature ())! = NULL) {// get the attribute information of this layer ogrfeaturedefn * pofdefn = polayer-> getlayerdefn (); int ifield; For (ifield = 0; ifield <pofdefn-> getfieldcount (); ifield ++) {// obtain the information of a field ogrfielddefn * pofielddefn = pofdefn-> getfielddefn (ifield ); if (pofielddefn-> GetType () = oftinteger) printf ("% d,", pofeature-> getfieldasinteger (ifield);} ogrgeometry * pogeometry; // obtain the feature pogeometry = pofeature-> getgeometryr EF (); // use the wkbflatten macro to convert the wkbpoint25d type to the wkbpoint type if (pogeometry! = NULL & wkbflatten (pogeometry-> getgeometrytype () = wkbpoint) {ogrpoint * popoint = (ogrpoint *) pogeometry; printf ("%. 3f, % 3. f \ n ", popoint-> getx (), popoint-> Gety ();} else printf (" No point geometry \ n "); // destroy feature ogrfeature :: destroyfeature (pofeature);} // destroy the data source to close the Vector file ogrdatasource: destroydatasource (pods );}

The gdal/OGR Library provides support for vector and raster file data.

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.