|
|
(Není zobrazeno 21 mezilehlých verzí od stejného uživatele.) |
Řádek 1: |
Řádek 1: |
| {{Upravit}} | | {{freegiswiki|OGR / Ukázka použití}} |
| | |
| Tato stránka obsahuje ukázku zdrojového textu demonstračního programu využívající pro přístup k vektorovým datům knihovnu '''[[GDAL/OGR|OGR]]'''. Program je inspirován skriptem z [[153GIS2 2009 - 10. cvičení|cvičení GIS2]].
| |
| | |
| == C++ ==
| |
| | |
| <source lang="cpp">
| |
| #include <iostream>
| |
| #include "ogrsf_frmts.h"
| |
| | |
| using std::cout;
| |
| using std::cerr;
| |
| using std::endl;
| |
| | |
| int main(int argc, char **argv)
| |
| {
| |
| const char *filename;
| |
|
| |
| OGRDataSource *poDS;
| |
| OGRLayer *poLayer;
| |
| OGRFeatureDefn *poFDefn;
| |
| | |
| if (argc != 2) {
| |
| cerr << "Pouziti: " << argv[0] << " shapefile" << endl;
| |
| return 1;
| |
| }
| |
|
| |
| filename = argv[1];
| |
|
| |
| // registrovat dostupne OGR ovladace
| |
| OGRRegisterAll();
| |
| | |
| // otevrit ShapeFile pro cteni
| |
| poDS = OGRSFDriverRegistrar::Open(filename, FALSE);
| |
| if (poDS == NULL) {
| |
| cerr << "Otevreni '" << filename << "' selhalo." << endl;
| |
| return 1;
| |
| }
| |
|
| |
| // nacist prvni OGR vrstvu (tj. Shapefile)
| |
| poLayer = poDS->GetLayer(0);
| |
| if (poLayer == NULL) {
| |
| cerr << "Nelze nacist OGR vrstvu." << endl;
| |
| return 1;
| |
| }
| |
| | |
| // ziskat informace o vrstve
| |
| poFDefn = poLayer->GetLayerDefn();
| |
| | |
| cout << "Detekovana OGR vrstva '" << poFDefn->GetName() << "'.\n\n";
| |
| | |
| for(int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
| |
| // ziskat informace o atributovem sloupci
| |
| OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
| |
| cout << poFieldDefn->GetNameRef() << endl;
| |
| }
| |
| | |
| return 0;
| |
| }
| |
| </source>
| |
| | |
| == Související články ==
| |
| | |
| * [[153GIS2 2009 - 10. cvičení - GRASS GIS|Ukázka skriptů pro GRASS GIS]]
| |
| | |
| == Externí odkazy ==
| |
| | |
| * [http://gdal.osgeo.org/ogr/hierarchy.html OGR API]
| |
| * [http://gdal.osgeo.org/ogr/ogr_apitut.html OGR API Tutorial]
| |
| * [http://gdal.osgeo.org/ogr/ogr_arch.html OGR Architecture]
| |
| | |
| {{GFOSS}}
| |
| {{Programování}}
| |
| {{C++}}
| |
| {{Python}}
| |