OGR读取Oracle Spatial数据


#include "ogrsf_frmts.h"

int main()
{
OGRRegisterAll();

OGRDataSource *pogrDataSource = NULL;
OGRLayer *pogrLayer = NULL;
OGRFeature *pogrFeature = NULL;
OGRGeometry *pogrGeometry = NULL;
OGRFeatureDefn *pogrFeatureDefn = NULL;
OGRFieldDefn *pogrFieldDefn = NULL;

//const char* uri = "/home/hawk/data/gis/beijing/beijing_Pt.shp";
//const char* uri = "PG:dbname='GBSDE' host='127.0.0.1' port='5432' user='GBSDE' password='GBSDE'";
const char* uri = "OCI:GBSDE/GBSDE@oradb8";
const char* szLayerName = "CITIES";

pogrDataSource = OGRSFDriverRegistrar::Open(uri,FALSE);
if(pogrDataSource==NULL)
{
printf("open failed.\n");
exit(1);
}

pogrLayer = pogrDataSource->GetLayerByName(szLayerName);
pogrLayer->ResetReading();

while((pogrFeature=pogrLayer->GetNextFeature())!=NULL)
{
pogrFeatureDefn = pogrLayer->GetLayerDefn();
for(int i=0; i<pogrFeatureDefn->GetFieldCount(); i++)
{
pogrFieldDefn = pogrFeatureDefn->GetFieldDefn(i);
}
pogrGeometry = pogrFeature->GetGeometryRef();
if(pogrGeometry!=NULL)
{
printf("%s\n", pogrGeometry->exportToKML());
}

OGRFeature::DestroyFeature(pogrFeature);
}

OGRDataSource::DestroyDataSource(pogrDataSource);
}

转载自:https://blog.csdn.net/marsrprj/article/details/83566477

You may also like...