本文整理汇总了C++中OGRFeature::GetFieldCount方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::GetFieldCount方法的具体用法?C++ OGRFeature::GetFieldCount怎么用?C++ OGRFeature::GetFieldCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeature
的用法示例。
在下文中一共展示了OGRFeature::GetFieldCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFeatureClass
QString QgsShapeFile::getFeatureClass(){
OGRFeature *feat = ogrLayer->GetNextFeature();
if(feat){
OGRGeometry *geom = feat->GetGeometryRef();
if(geom){
geom_type = QString(geom->getGeometryName());
char * esc_str = new char[geom_type.length()*2+1];
PQescapeString(esc_str, (const char *)geom_type, geom_type.length());
geom_type = QString(esc_str);
delete[] esc_str;
QString file(filename);
file.replace(file.length()-3, 3, "dbf");
// open the dbf file
std::ifstream dbf((const char*)file, std::ios::in | std::ios::binary);
// read header
DbaseHeader dbh;
dbf.read((char *)&dbh, sizeof(dbh));
Fda fda;
QString str_type = "varchar(";
for(int field_count = 0, bytes_read = sizeof(dbh); bytes_read < dbh.size_hdr-1; field_count++, bytes_read +=sizeof(fda)){
dbf.read((char *)&fda, sizeof(fda));
switch(fda.field_type){
case 'N': if((int)fda.field_decimal>0)
column_types.push_back("float");
else
column_types.push_back("int");
break;
case 'F': column_types.push_back("float");
break;
case 'D': column_types.push_back("date");
break;
case 'C':
str_type= QString("varchar(%1)").arg(fda.field_length);
column_types.push_back(str_type);
break;
case 'L': column_types.push_back("boolean");
break;
default:
column_types.push_back("varchar(256)");
break;
}
}
dbf.close();
int numFields = feat->GetFieldCount();
for(int n=0; n<numFields; n++)
column_names.push_back(feat->GetFieldDefnRef(n)->GetNameRef());
}else valid = false;
delete feat;
}else valid = false;
ogrLayer->ResetReading();
return valid?geom_type:NULL;
}
示例2: switch
static swq_expr_node *OGRFeatureFetcher( swq_expr_node *op, void *pFeatureIn )
{
OGRFeature *poFeature = (OGRFeature *) pFeatureIn;
swq_expr_node *poRetNode = NULL;
if( op->field_type == SWQ_GEOMETRY )
{
int iField = op->field_index - (poFeature->GetFieldCount() + SPECIAL_FIELD_COUNT);
poRetNode = new swq_expr_node( poFeature->GetGeomFieldRef(iField) );
return poRetNode;
}
switch( op->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger(op->field_index) );
break;
case SWQ_INTEGER64:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger64(op->field_index) );
break;
case SWQ_FLOAT:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsDouble(op->field_index) );
break;
default:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsString(op->field_index) );
break;
}
poRetNode->is_null = !(poFeature->IsFieldSet(op->field_index));
return poRetNode;
}
示例3: CPLDebug
OGRFeature *OGRGeoconceptLayer::GetNextFeature()
{
OGRFeature* poFeature = NULL;
for( ;; )
{
if( !(poFeature= (OGRFeature*)ReadNextFeature_GCIO(_gcFeature)) )
{
/*
* As several features are embed in the Geoconcept file,
* when reaching the end of the feature type, resetting
* the reader would allow reading other features :
* ogrinfo -ro export.gxt FT1 FT2 ...
* will be all features for all features types !
*/
Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature),NULL);
break;
}
if( (m_poFilterGeom == NULL || FilterGeometry( poFeature->GetGeometryRef() ) )
&&
(m_poAttrQuery == NULL || m_poAttrQuery->Evaluate( poFeature )) )
{
break;
}
delete poFeature;
}
CPLDebug( "GEOCONCEPT",
"FID : %ld\n"
"%s : %s",
poFeature? poFeature->GetFID():-1L,
poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldDefnRef(0)->GetNameRef():"-",
poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldAsString(0):"");
return poFeature;
}
示例4: Open
int OGRAmigoCloudDataSource::Open( const char * pszFilename,
char** papszOpenOptionsIn,
int bUpdateIn )
{
bReadWrite = CPL_TO_BOOL(bUpdateIn);
pszName = CPLStrdup( pszFilename );
if( CSLFetchNameValue(papszOpenOptionsIn, "PROJECTID") )
pszProjetctId = CPLStrdup(CSLFetchNameValue(papszOpenOptionsIn, "PROJECTID"));
else
{
pszProjetctId = CPLStrdup(pszFilename + strlen("AMIGOCLOUD:"));
char* pchSpace = strchr(pszProjetctId, ' ');
if( pchSpace )
*pchSpace = '\0';
if( pszProjetctId[0] == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing projetc id");
return FALSE;
}
}
osAPIKey = CSLFetchNameValueDef(papszOpenOptionsIn, "API_KEY",
CPLGetConfigOption("AMIGOCLOUD_API_KEY", ""));
CPLString osDatasets = OGRAMIGOCLOUDGetOptionValue(pszFilename, "datasets");
bUseHTTPS = CPLTestBool(CPLGetConfigOption("AMIGOCLOUD_HTTPS", "YES"));
OGRLayer* poSchemaLayer = ExecuteSQLInternal("SELECT current_schema()");
if( poSchemaLayer )
{
OGRFeature* poFeat = poSchemaLayer->GetNextFeature();
if( poFeat )
{
if( poFeat->GetFieldCount() == 1 )
{
osCurrentSchema = poFeat->GetFieldAsString(0);
}
delete poFeat;
}
ReleaseResultSet(poSchemaLayer);
}
if( osCurrentSchema.size() == 0 )
return FALSE;
if (osDatasets.size() != 0)
{
char** papszTables = CSLTokenizeString2(osDatasets, ",", 0);
for(int i=0;papszTables && papszTables[i];i++)
{
papoLayers = (OGRAmigoCloudTableLayer**) CPLRealloc(
papoLayers, (nLayers + 1) * sizeof(OGRAmigoCloudTableLayer*));
papoLayers[nLayers ++] = new OGRAmigoCloudTableLayer(this, papszTables[i]);
}
CSLDestroy(papszTables);
return TRUE;
}
return TRUE;
}
示例5: Open
int OGRAmigoCloudDataSource::Open( const char * pszFilename,
char** papszOpenOptionsIn,
int bUpdateIn )
{
bReadWrite = CPL_TO_BOOL(bUpdateIn);
pszName = CPLStrdup( pszFilename );
pszProjectId = CPLStrdup(pszFilename + strlen("AMIGOCLOUD:"));
char* pchSpace = strchr(pszProjectId, ' ');
if( pchSpace )
*pchSpace = '\0';
if( pszProjectId[0] == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing project id");
return FALSE;
}
osAPIKey = CSLFetchNameValueDef(papszOpenOptionsIn, "AMIGOCLOUD_API_KEY",
CPLGetConfigOption("AMIGOCLOUD_API_KEY", ""));
if (osAPIKey.empty())
{
osAPIKey = OGRAMIGOCLOUDGetOptionValue(pszFilename, "AMIGOCLOUD_API_KEY");
}
if (osAPIKey.empty())
{
CPLError(CE_Failure, CPLE_AppDefined, "AMIGOCLOUD_API_KEY is not defined.\n");
return FALSE;
}
OGRLayer* poSchemaLayer = ExecuteSQLInternal("SELECT current_schema()");
if( poSchemaLayer )
{
OGRFeature* poFeat = poSchemaLayer->GetNextFeature();
if( poFeat )
{
if( poFeat->GetFieldCount() == 1 )
{
osCurrentSchema = poFeat->GetFieldAsString(0);
}
delete poFeat;
}
ReleaseResultSet(poSchemaLayer);
}
if( osCurrentSchema.empty() )
return FALSE;
CPLString osDatasets = OGRAMIGOCLOUDGetOptionValue(pszFilename, "datasets");
if (!osDatasets.empty())
{
char** papszTables = CSLTokenizeString2(osDatasets, ",", 0);
for(int i=0;papszTables && papszTables[i];i++)
{
papoLayers = (OGRAmigoCloudTableLayer**) CPLRealloc(
papoLayers, (nLayers + 1) * sizeof(OGRAmigoCloudTableLayer*));
papoLayers[nLayers ++] = new OGRAmigoCloudTableLayer(this, papszTables[i]);
}
CSLDestroy(papszTables);
// If OVERWRITE: YES, truncate the layer.
if( nLayers==1 &&
CPLFetchBool(papszOpenOptionsIn, "OVERWRITE", false) )
{
TruncateDataset(papoLayers[0]->GetTableName());
}
return TRUE;
} else {
// If 'datasets' word is in the filename, but no dataset id specified,
// print the list of available datasets
if(std::string(pszFilename).find("datasets") != std::string::npos)
ListDatasets();
}
return TRUE;
}
示例6: if
int ILI1Reader::ReadTable(const char *layername) {
char **tokens = NULL;
const char *firsttok = NULL;
int ret = TRUE;
int warned = FALSE;
int fIndex;
int geomIdx;
// curLayer is NULL if we have more than one
// point geometry column
if(curLayer == NULL) {
OGRFeature *metaFeature = NULL;
metaLayer->ResetReading();
while((metaFeature = metaLayer->GetNextFeature()) != NULL ) {
if(EQUAL(layername, metaFeature->GetFieldAsString(0))) {
const char *geomlayername = metaFeature->GetFieldAsString(2);
curLayer = GetLayerByName(geomlayername);
break;
}
}
}
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
OGRFeature *feature = NULL;
// get the geometry index of the current layer
// only if the model is read
if(featureDef->GetFieldCount() != 0) {
OGRFeature *metaFeature = NULL;
metaLayer->ResetReading();
while((metaFeature = metaLayer->GetNextFeature()) != NULL ) {
if(EQUAL(curLayer->GetLayerDefn()->GetName(), metaFeature->GetFieldAsString(2))) {
geomIdx = metaFeature->GetFieldAsInteger(1);
}
}
}
long fpos = VSIFTell(fpItf);
while (ret && (tokens = ReadParseLine()))
{
firsttok = CSLGetField(tokens, 0);
if (EQUAL(firsttok, "OBJE"))
{
//Check for features spread over multiple objects
if (featureDef->GetGeomType() == wkbPolygon)
{
//Multiple polygon rings
feature = curLayer->GetFeatureRef(atol(CSLGetField(tokens, 2)));
}
else if (featureDef->GetGeomType() == wkbGeometryCollection)
{
//AREA lines spread over mutltiple objects
}
else
{
feature = NULL;
}
if (feature == NULL)
{
if (featureDef->GetFieldCount() == 0)
{
CPLDebug( "OGR_ILI", "No field definition found for table: %s", featureDef->GetName() );
//Model not read - use heuristics
for (fIndex=1; fIndex<CSLCount(tokens); fIndex++)
{
char szFieldName[32];
sprintf(szFieldName, "Field%02d", fIndex);
OGRFieldDefn oFieldDefn(szFieldName, OFTString);
featureDef->AddFieldDefn(&oFieldDefn);
}
}
//start new feature
feature = new OGRFeature(featureDef);
int fieldno = 0;
for (fIndex=1; fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount(); fIndex++, fieldno++)
{
if (!EQUAL(tokens[fIndex], "@")) {
//CPLDebug( "READ TABLE OGR_ILI", "Adding Field %d: %s", fieldno, tokens[fIndex]);
feature->SetField(fieldno, tokens[fIndex]);
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTReal
&& fieldno > 0
&& featureDef->GetFieldDefn(fieldno-1)->GetType() == OFTReal
&& featureDef->GetGeomType() == wkbPoint
/*
// if there is no ili model read,
// we have no chance to detect the
// geometry column!!
*/
&& (fieldno-2) == geomIdx) {
//add Point geometry
OGRPoint *ogrPoint = new OGRPoint(atof(tokens[fIndex-1]), atof(tokens[fIndex]));
feature->SetGeometryDirectly(ogrPoint);
}
}
}
if (!warned && featureDef->GetFieldCount() != CSLCount(tokens)-1 && !(featureDef->GetFieldCount() == CSLCount(tokens) && EQUAL(featureDef->GetFieldDefn(featureDef->GetFieldCount()-1)->GetNameRef(), "ILI_Geometry"))) {
//.........这里部分代码省略.........
示例7: oFieldDefn
int ILI1Reader::ReadTable(CPL_UNUSED const char *layername) {
char **tokens = NULL;
int ret = TRUE;
int warned = FALSE;
int geomIdx = -1;
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
OGRFeature *feature = NULL;
bool bFeatureAdded = false;
while (ret && (tokens = ReadParseLine()) != NULL)
{
const char *firsttok = CSLGetField(tokens, 0);
if (EQUAL(firsttok, "OBJE"))
{
if (featureDef->GetFieldCount() == 0 && curLayer->GetFeatureCount() == 0)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No field definition found for table: %s",
featureDef->GetName() );
// Model not read - use heuristics.
for( int fIndex=1; fIndex<CSLCount(tokens); fIndex++ )
{
char szFieldName[32];
snprintf(szFieldName, sizeof(szFieldName), "Field%02d", fIndex);
OGRFieldDefn oFieldDefn(szFieldName, OFTString);
featureDef->AddFieldDefn(&oFieldDefn);
}
}
//start new feature
if( !bFeatureAdded )
delete feature;
feature = new OGRFeature(featureDef);
for( int fIndex=1, fieldno = 0;
fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount();
fIndex++, fieldno++ )
{
if (!(tokens[fIndex][0] == codeUndefined && tokens[fIndex][1] == '\0')) {
#ifdef DEBUG_VERBOSE
CPLDebug( "READ TABLE OGR_ILI", "Setting Field %d (Type %d): %s",
fieldno, featureDef->GetFieldDefn(fieldno)->GetType(),
tokens[fIndex] );
#endif
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTString) {
// Interlis 1 encoding is ISO 8859-1 (Latin1) -> Recode to UTF-8
char* pszRecoded = CPLRecode(
tokens[fIndex], CPL_ENC_ISO8859_1, CPL_ENC_UTF8);
// Replace space marks
for( char* pszString = pszRecoded;
*pszString != '\0';
pszString++ ) {
if (*pszString == codeBlank) *pszString = ' ';
}
feature->SetField(fieldno, pszRecoded);
CPLFree(pszRecoded);
} else {
feature->SetField(fieldno, tokens[fIndex]);
}
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTReal
&& fieldno > 0
&& featureDef->GetFieldDefn(fieldno-1)->GetType() == OFTReal) {
// Check for Point geometry (Coord type).
// If there is no ili model read,
// we have no chance to detect the
// geometry column.
CPLString geomfldname
= featureDef->GetFieldDefn(fieldno)->GetNameRef();
// Check if name ends with _1.
if (geomfldname.size() >= 2 && geomfldname[geomfldname.size()-2]
== '_') {
geomfldname = geomfldname.substr(0, geomfldname.size()-2);
geomIdx = featureDef->GetGeomFieldIndex(geomfldname.c_str());
if (geomIdx == -1)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No matching definition for field '%s' of "
"table %s found",
geomfldname.c_str(), featureDef->GetName() );
}
} else {
geomIdx = -1;
}
if (geomIdx >= 0) {
if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint) {
// Add Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-1]), CPLAtof(tokens[fIndex]));
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
} else if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint25D && fieldno > 1 &&
featureDef->GetFieldDefn(fieldno-2)->GetType() ==
OFTReal) {
// Add 3D Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-2]), CPLAtof(tokens[fIndex-1]),
CPLAtof(tokens[fIndex]) );
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
}
//.........这里部分代码省略.........
示例8: CalAsShp
void DataCvt_Log::CalAsShp()
{
double ptmptime_start = MPI_Wtime();
OGRRegisterAll();
//create a new shp to caculate
CBaseOperate pbaseOperate;
if(rankid==0)
{
pbaseOperate.CreateCopyShp(m_DatasourceConStr.c_str(),m_PathOrTableName.c_str(),m_ResultPathOrTableName.c_str());
}
MPI_Barrier(MPI_COMM_WORLD);
string pLayerName = m_ResultPathOrTableName;
if(strcmp(m_DatasourceConStr.c_str(),"")==0)//input is shp file
{
m_DatasourceConStr = m_ResultPathOrTableName;
string pShpPath = m_ResultPathOrTableName;
string p_LayerName = GetFileNameOnly(pShpPath.c_str());
int pindex = p_LayerName.find_first_of('.');
pLayerName = p_LayerName.erase(pindex,p_LayerName.size()-1);
}
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(m_DatasourceConStr.c_str(),TRUE);
OGRLayer* poLayer = poDS->GetLayerByName(pLayerName.c_str());
OGRFeature * pFeature =poLayer->GetNextFeature();
m_RowNum = poLayer->GetFeatureCount();
//if -c argv is null, all field will be used
m_ColNum= pFeature->GetFieldCount();
if(c_CaculateCols.size()==0)
{
if(rankid==0)
cout<<"!!!!!!! No input columns ids, all fields in the input file will be used..."<<endl<<endl;
for(int i=0;i<m_ColNum;i++)
{
c_CaculateCols.push_back(i);
}
}
double ptmptime_end = MPI_Wtime();
m_GdalIOInCal_Time=m_GdalIOInCal_Time+ptmptime_end-ptmptime_start;
//assign number to each process
int pnum_start,pnum_end;
int pMyProcessNum=0; int pRemainder=m_RowNum%numproc;
if(rankid<pRemainder)
{
pMyProcessNum = m_RowNum/numproc+1;
pnum_start = rankid*pMyProcessNum;
pnum_end = pnum_start+pMyProcessNum-1;
}
else
{
pMyProcessNum = m_RowNum/numproc;
pnum_start = pRemainder*(pMyProcessNum+1)+(rankid-pRemainder)*pMyProcessNum;
pnum_end = pnum_start+pMyProcessNum-1;
}
//postgis: fid begins from 1, not 0
string pwhere="";
if(strcmp(m_DatasourceConStr.substr(0,3).c_str(),"PG:")==0)//input is postgis
{
pwhere = "gid>="+toString(pnum_start+1)+" and gid<="+toString(pnum_end+1);
}
else//shpfile: fid begins from 0, not 1
{
pwhere = "fid>="+toString(pnum_start)+" and fid<="+toString(pnum_end);
}
poLayer->SetAttributeFilter(pwhere.c_str());
pFeature = poLayer->GetNextFeature();
while(pFeature!=NULL)
{
for(int i=0;i<c_CaculateCols.size();i++)
{
double tmp = pFeature->GetFieldAsDouble(c_CaculateCols[i]);
if(tmp!=0)
tmp = log(fabs(tmp));
else
tmp=0;
double pstart = MPI_Wtime();
pFeature->SetField(c_CaculateCols[i],tmp);
poLayer->SetFeature(pFeature);
double pend = MPI_Wtime();
m_GdalIOInCal_Time = m_GdalIOInCal_Time+pend-pstart;
}
pFeature = poLayer->GetNextFeature();
}
OGRDataSource::DestroyDataSource( poDS );
double ptmptime_endall = MPI_Wtime();
Mpi_Caculate_Time = ptmptime_endall-ptmptime_start-m_GdalIOInCal_Time;
double tmp=Mpi_Caculate_Time;
MPI_Reduce(&Mpi_Caculate_Time,&tmp,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD);
Mpi_Caculate_Time = tmp;
}
示例9: Open
int OGRCARTODataSource::Open( const char * pszFilename,
char** papszOpenOptionsIn,
int bUpdateIn )
{
bReadWrite = bUpdateIn;
bBatchInsert = CPLTestBool(CSLFetchNameValueDef(papszOpenOptionsIn, "BATCH_INSERT", "YES"));
pszName = CPLStrdup( pszFilename );
if( CSLFetchNameValue(papszOpenOptionsIn, "ACCOUNT") )
pszAccount = CPLStrdup(CSLFetchNameValue(papszOpenOptionsIn, "ACCOUNT"));
else
{
if( STARTS_WITH_CI(pszFilename, "CARTODB:") )
pszAccount = CPLStrdup(pszFilename + strlen("CARTODB:"));
else
pszAccount = CPLStrdup(pszFilename + strlen("CARTO:"));
char* pchSpace = strchr(pszAccount, ' ');
if( pchSpace )
*pchSpace = '\0';
if( pszAccount[0] == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing account name");
return FALSE;
}
}
osAPIKey = CSLFetchNameValueDef(papszOpenOptionsIn, "API_KEY",
CPLGetConfigOption("CARTO_API_KEY",
CPLGetConfigOption("CARTODB_API_KEY", "")));
CPLString osTables = OGRCARTOGetOptionValue(pszFilename, "tables");
/*if( osTables.size() == 0 && osAPIKey.size() == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"When not specifying tables option, CARTO_API_KEY must be defined");
return FALSE;
}*/
bUseHTTPS = CPLTestBool(CPLGetConfigOption("CARTO_HTTPS",
CPLGetConfigOption("CARTODB_HTTPS", "YES")));
OGRLayer* poSchemaLayer = ExecuteSQLInternal("SELECT current_schema()");
if( poSchemaLayer )
{
OGRFeature* poFeat = poSchemaLayer->GetNextFeature();
if( poFeat )
{
if( poFeat->GetFieldCount() == 1 )
{
osCurrentSchema = poFeat->GetFieldAsString(0);
}
delete poFeat;
}
ReleaseResultSet(poSchemaLayer);
}
if( osCurrentSchema.size() == 0 )
return FALSE;
/* -------------------------------------------------------------------- */
/* Find out PostGIS version */
/* -------------------------------------------------------------------- */
if( bReadWrite )
{
OGRLayer* poPostGISVersionLayer = ExecuteSQLInternal("SELECT postgis_version()");
if( poPostGISVersionLayer )
{
OGRFeature* poFeat = poPostGISVersionLayer->GetNextFeature();
if( poFeat )
{
if( poFeat->GetFieldCount() == 1 )
{
const char* pszVersion = poFeat->GetFieldAsString(0);
nPostGISMajor = atoi(pszVersion);
const char* pszDot = strchr(pszVersion, '.');
nPostGISMinor = 0;
if( pszDot )
nPostGISMinor = atoi(pszDot + 1);
}
delete poFeat;
}
ReleaseResultSet(poPostGISVersionLayer);
}
}
if( osAPIKey.size() && bUpdateIn )
{
ExecuteSQLInternal(
"DROP FUNCTION IF EXISTS ogr_table_metadata(TEXT,TEXT); "
"CREATE OR REPLACE FUNCTION ogr_table_metadata(schema_name TEXT, table_name TEXT) RETURNS TABLE "
"(attname TEXT, typname TEXT, attlen INT, format_type TEXT, "
"attnum INT, attnotnull BOOLEAN, indisprimary BOOLEAN, "
"defaultexpr TEXT, dim INT, srid INT, geomtyp TEXT, srtext TEXT) AS $$ "
"SELECT a.attname::text, t.typname::text, a.attlen::int, "
"format_type(a.atttypid,a.atttypmod)::text, "
"a.attnum::int, "
"a.attnotnull::boolean, "
"i.indisprimary::boolean, "
"pg_get_expr(def.adbin, c.oid)::text AS defaultexpr, "
//.........这里部分代码省略.........
示例10: OpenRasterScene
//.........这里部分代码省略.........
{
json_object* poProducts = json_object_object_get(poData, "products");
if( poProducts != NULL && json_object_get_type(poProducts) == json_type_object )
{
json_object* poProduct = json_object_object_get(poProducts, pszProductType);
if( poProduct != NULL && json_object_get_type(poProduct) == json_type_object )
{
json_object* poFull = json_object_object_get(poProduct, "full");
if( poFull && json_object_get_type(poFull) == json_type_string )
pszLink = json_object_get_string(poFull);
}
}
}
}
osRasterURL = pszLink ? pszLink : "";
json_object_put(poObj);
if( osRasterURL.size() == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot find link to scene %s",
osScene.c_str());
return NULL;
}
if( strncmp(osRasterURL, "http://", strlen("http://")) == 0 )
{
osRasterURL = "http://" + osAPIKey + ":@" + osRasterURL.substr(strlen("http://"));
}
else if( strncmp(osRasterURL, "https://", strlen("https://")) == 0 )
{
osRasterURL = "https://" + osAPIKey + ":@" + osRasterURL.substr(strlen("https://"));
}
CPLString osOldHead(CPLGetConfigOption("CPL_VSIL_CURL_USE_HEAD", ""));
CPLString osOldExt(CPLGetConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", ""));
int bUseVSICURL = CSLFetchBoolean(poOpenInfo->papszOpenOptions, "RANDOM_ACCESS", TRUE);
if( bUseVSICURL && !(strncmp(osBaseURL, "/vsimem/", strlen("/vsimem/")) == 0) )
{
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD", "NO");
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", "{noext}");
VSIStatBufL sStat;
if( VSIStatL(("/vsicurl/" + osRasterURL).c_str(), &sStat) == 0 &&
sStat.st_size > 0 )
{
osRasterURL = "/vsicurl/" + osRasterURL;
}
else
{
CPLDebug("PLSCENES", "Cannot use random access for that file");
}
}
GDALDataset* poOutDS = (GDALDataset*) GDALOpen(osRasterURL, GA_ReadOnly);
if( poOutDS )
{
poOutDS->SetDescription(poOpenInfo->pszFilename);
poOutDS->GetFileList(); /* so as to probe all auxiliary files before reseting the allowed extensions */
if( !EQUAL(pszProductType, "thumb") )
{
OGRPLScenesLayer* poLayer = new OGRPLScenesLayer(this, "ortho",
(osBaseURL + "ortho/").c_str());
papoLayers = (OGRPLScenesLayer**) CPLRealloc(papoLayers,
sizeof(OGRPLScenesLayer*) * (nLayers + 1));
papoLayers[nLayers ++] = poLayer;
/* Attach scene matadata */
poLayer->SetAttributeFilter(CPLSPrintf("id = '%s'", osScene.c_str()));
OGRFeature* poFeat = poLayer->GetNextFeature();
if( poFeat )
{
for(int i=0;i<poFeat->GetFieldCount();i++)
{
if( poFeat->IsFieldSet(i) )
{
const char* pszKey = poFeat->GetFieldDefnRef(i)->GetNameRef();
const char* pszVal = poFeat->GetFieldAsString(i);
if( strstr(pszKey, "file_size") == NULL &&
strstr(pszVal, "https://") == NULL )
{
poOutDS->SetMetadataItem(pszKey, pszVal);
}
}
}
}
delete poFeat;
}
}
if( bUseVSICURL )
{
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD",
osOldHead.size() ? osOldHead.c_str(): NULL);
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS",
osOldExt.size() ? osOldExt.c_str(): NULL);
}
return poOutDS;
}
示例11: load
bool Shape::load(const std::string& filename) {
GDALAllRegister();
GDALDataset* poDS;
poDS = (GDALDataset*)GDALOpenEx(filename.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL);
if (poDS == NULL) return false;
// 初期化
shapeObjects.clear();
minBound.x = std::numeric_limits<float>::max();
minBound.y = std::numeric_limits<float>::max();
minBound.z = std::numeric_limits<float>::max();
maxBound.x = -std::numeric_limits<float>::max();
maxBound.y = -std::numeric_limits<float>::max();
maxBound.z = -std::numeric_limits<float>::max();
int nLayers = poDS->GetLayerCount();
int i = 0;
for (int n = 0; n < nLayers; ++n) {
OGRLayer* poLayer = poDS->GetLayer(n);
shapeType = poLayer->GetGeomType();
shapeObjects.resize(shapeObjects.size() + poLayer->GetFeatureCount());
OGRFeature* poFeature;
poLayer->ResetReading();
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
// 属性の名前を読み込む
std::vector<std::string> fieldNames;
for (int j = 0; j < poFeature->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFeature->GetFieldDefnRef(j);
fieldNames.push_back(poFieldDefn->GetNameRef());
}
// 属性の値を読み込む
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
for (int j = 0; j < poFDefn->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(j);
if (poFieldDefn->GetType() == OFTInteger) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTInteger64) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTReal) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsDouble(j));
}
else if (poFieldDefn->GetType() == OFTString) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
else {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
}
// このshapeのベクトルデータを読み込む
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if (poGeometry != NULL) {
if (wkbFlatten(poGeometry->getGeometryType()) == wkbPoint) {
shapeObjects[i].parts.resize(1);
shapeObjects[i].parts[0].points.resize(1);
OGRPoint* poPoint = (OGRPoint*)poGeometry;
shapeObjects[i].parts[0].points[0].x = poPoint->getX();
shapeObjects[i].parts[0].points[0].y = poPoint->getY();
updateBounds(poPoint);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString) {
OGRLineString* poLineString = (OGRLineString*)poGeometry;
readLineString(poLineString, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon) {
OGRPolygon* poPolygon = (OGRPolygon*)poGeometry;
readPolygon(poPolygon, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon) {
OGRMultiPolygon* poMultiPolygon = (OGRMultiPolygon*)poGeometry;
readMultiPolygon(poMultiPolygon, shapeObjects[i]);
}
else {
// not supported
}
}
// shapeObjectsのインデックスをインクリメント
i++;
// OGRが取得したメモリを開放
OGRFeature::DestroyFeature(poFeature);
}
}
GDALClose(poDS);
return true;
}