本文整理汇总了C++中OGRFieldDefn::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFieldDefn::GetType方法的具体用法?C++ OGRFieldDefn::GetType怎么用?C++ OGRFieldDefn::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFieldDefn
的用法示例。
在下文中一共展示了OGRFieldDefn::GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ogrReadListColumn
SEXP ogrReadListColumn(OGRLayer *poLayer, SEXP FIDs, int iField, int k, int int64) {
// read feature data and return something according to the type
OGRFeatureDefn *poDefn;
OGRFieldDefn *poField;
OGRFeature *poFeature;
int iRow,nRows,nlist;
SEXP ans = R_NilValue;
nRows=length(FIDs);
// get field data from layer
installErrorHandler();
poDefn = poLayer->GetLayerDefn();
poField = poDefn->GetFieldDefn(iField);
uninstallErrorHandlerAndTriggerError();
if(poField == NULL) {
error("Error getting field %d ",iField);
}
// allocate an object for the result depending on the feature type:
installErrorHandler();
switch(poField->GetType()) {
case OFTIntegerList:
PROTECT(ans=allocVector(INTSXP,nRows));
break;
#ifdef GDALV2
case OFTInteger64List:
if (int64 == 3) {
PROTECT(ans=allocVector(STRSXP,nRows));
} else {
PROTECT(ans=allocVector(INTSXP,nRows));
}
break;
#endif
case OFTRealList:
PROTECT(ans=allocVector(REALSXP,nRows));
break;
case OFTStringList:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
default:
const char *desc = poField->GetFieldTypeName(poField->GetType());
uninstallErrorHandlerAndTriggerError();
error("unsupported field type: %s", desc);
break;
}
uninstallErrorHandlerAndTriggerError();
// now go over each row and retrieve data. iRow is an index in a
// vector of FIDs
installErrorHandler();
poLayer->ResetReading();
OGRField* psField;
iRow = 0;
while((poFeature = poLayer->GetNextFeature()) != NULL) {
if (poFeature->IsFieldSet(iField)) {
// now get the value using the right type:
psField = poFeature->GetRawFieldRef(iField);
switch(poField->GetType()) {
case OFTIntegerList:
nlist = psField->IntegerList.nCount;
if (k < nlist)
INTEGER(ans)[iRow] = psField->IntegerList.paList[k];
else INTEGER(ans)[iRow]=NA_INTEGER;
break;
#ifdef GDALV2
case OFTInteger64List:
nlist = psField->Integer64List.nCount;
if (k < nlist) {
if (int64 == 3) {
// FIXME clang++
// GIntBig nVal64 = psField->Integer64List.paList[k];
char szItem[32];
snprintf(szItem, sizeof(szItem), CPL_FRMT_GIB,
psField->Integer64List.paList[k]);
SET_STRING_ELT(ans, iRow, mkChar(szItem));
} else {
GIntBig nVal64 = psField->Integer64List.paList[k];
int nVal = (nVal64 > INT_MAX) ? INT_MAX :
(nVal64 < INT_MIN) ? INT_MIN : (int) nVal64;
if (((GIntBig)nVal != nVal64) && int64 == 2) {
warning("Integer64 value clamped: feature %d", iRow);
}
INTEGER(ans)[iRow]=nVal;
}
} else {
if (int64 == 3) {
SET_STRING_ELT(ans, iRow, NA_STRING);
} else {
INTEGER(ans)[iRow]=NA_INTEGER;
}
}
break;
#endif
case OFTRealList:
nlist = psField->RealList.nCount;
if (k < nlist)
REAL(ans)[iRow] = psField->RealList.paList[k];
//.........这里部分代码省略.........
示例2: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
const char* pszGeomField,
OGRGeometry *poSpatialFilter,
bool bListMDD,
bool bShowMetadata,
char** papszExtraMDDomains,
bool bFeatureCount,
bool bExtent,
const char* pszWKTFormat )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != nullptr )
{
if( poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE )
{
printf("FAILURE: SetAttributeFilter(%s) failed.\n", pszWHERE);
exit(1);
}
}
if( poSpatialFilter != nullptr )
{
if( pszGeomField != nullptr )
{
const int iGeomField = poDefn->GetGeomFieldIndex(pszGeomField);
if( iGeomField >= 0 )
poLayer->SetSpatialFilter(iGeomField, poSpatialFilter);
else
printf("WARNING: Cannot find geometry field %s.\n",
pszGeomField);
}
else
{
poLayer->SetSpatialFilter(poSpatialFilter);
}
}
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
if( !bSuperQuiet )
{
printf("\n");
printf("Layer name: %s\n", poLayer->GetName());
}
GDALInfoReportMetadata(static_cast<GDALMajorObjectH>(poLayer),
bListMDD,
bShowMetadata,
papszExtraMDDomains);
if( bVerbose )
{
const int nGeomFieldCount =
poLayer->GetLayerDefn()->GetGeomFieldCount();
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
printf("Geometry (%s): %s\n", poGFldDefn->GetNameRef(),
OGRGeometryTypeToName(poGFldDefn->GetType()));
}
}
else
{
printf("Geometry: %s\n",
OGRGeometryTypeToName(poLayer->GetGeomType()));
}
if( bFeatureCount )
printf("Feature Count: " CPL_FRMT_GIB "\n",
poLayer->GetFeatureCount());
OGREnvelope oExt;
if( bExtent && nGeomFieldCount > 1 )
{
for( int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
if( poLayer->GetExtent(iGeom, &oExt, TRUE) == OGRERR_NONE )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
CPLprintf("Extent (%s): (%f, %f) - (%f, %f)\n",
poGFldDefn->GetNameRef(),
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
}
}
else if( bExtent && poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE )
{
CPLprintf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
//.........这里部分代码省略.........
示例3: if
GIntBig *OGRFeatureQuery::EvaluateAgainstIndices( swq_expr_node *psExpr,
OGRLayer *poLayer,
GIntBig& nFIDCount )
{
OGRAttrIndex *poIndex;
/* -------------------------------------------------------------------- */
/* Does the expression meet our requirements? */
/* -------------------------------------------------------------------- */
if( psExpr == NULL ||
psExpr->eNodeType != SNT_OPERATION )
return NULL;
if ((psExpr->nOperation == SWQ_OR || psExpr->nOperation == SWQ_AND) &&
psExpr->nSubExprCount == 2)
{
GIntBig nFIDCount1 = 0, nFIDCount2 = 0;
GIntBig* panFIDList1 = EvaluateAgainstIndices( psExpr->papoSubExpr[0], poLayer, nFIDCount1 );
GIntBig* panFIDList2 = panFIDList1 == NULL ? NULL :
EvaluateAgainstIndices( psExpr->papoSubExpr[1], poLayer, nFIDCount2 );
GIntBig* panFIDList = NULL;
if (panFIDList1 != NULL && panFIDList2 != NULL)
{
if (psExpr->nOperation == SWQ_OR )
panFIDList = OGRORGIntBigArray(panFIDList1, nFIDCount1,
panFIDList2, nFIDCount2, nFIDCount);
else if (psExpr->nOperation == SWQ_AND )
panFIDList = OGRANDGIntBigArray(panFIDList1, nFIDCount1,
panFIDList2, nFIDCount2, nFIDCount);
}
CPLFree(panFIDList1);
CPLFree(panFIDList2);
return panFIDList;
}
if( !(psExpr->nOperation == SWQ_EQ || psExpr->nOperation == SWQ_IN)
|| psExpr->nSubExprCount < 2 )
return NULL;
swq_expr_node *poColumn = psExpr->papoSubExpr[0];
swq_expr_node *poValue = psExpr->papoSubExpr[1];
if( poColumn->eNodeType != SNT_COLUMN
|| poValue->eNodeType != SNT_CONSTANT )
return NULL;
poIndex = poLayer->GetIndex()->GetFieldIndex( poColumn->field_index );
if( poIndex == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* OK, we have an index, now we need to query it. */
/* -------------------------------------------------------------------- */
OGRField sValue;
OGRFieldDefn *poFieldDefn;
poFieldDefn = poLayer->GetLayerDefn()->GetFieldDefn(poColumn->field_index);
/* -------------------------------------------------------------------- */
/* Handle the case of an IN operation. */
/* -------------------------------------------------------------------- */
if (psExpr->nOperation == SWQ_IN)
{
int nLength;
GIntBig *panFIDs = NULL;
int iIN;
for( iIN = 1; iIN < psExpr->nSubExprCount; iIN++ )
{
switch( poFieldDefn->GetType() )
{
case OFTInteger:
if (psExpr->papoSubExpr[iIN]->field_type == SWQ_FLOAT)
sValue.Integer = (int) psExpr->papoSubExpr[iIN]->float_value;
else
sValue.Integer = (int) psExpr->papoSubExpr[iIN]->int_value;
break;
case OFTInteger64:
if (psExpr->papoSubExpr[iIN]->field_type == SWQ_FLOAT)
sValue.Integer64 = (GIntBig) psExpr->papoSubExpr[iIN]->float_value;
else
sValue.Integer64 = psExpr->papoSubExpr[iIN]->int_value;
break;
case OFTReal:
sValue.Real = psExpr->papoSubExpr[iIN]->float_value;
break;
case OFTString:
sValue.String = psExpr->papoSubExpr[iIN]->string_value;
break;
default:
CPLAssert( FALSE );
return NULL;
}
int nFIDCount32 = 0;
//.........这里部分代码省略.........
示例4: ogrInfo
//.........这里部分代码省略.........
pc++;
INTEGER(vec2)[0]=nFields;
SET_VECTOR_ELT(ans,1,vec2);
installErrorHandler();
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE) {
PROTECT(dvec=allocVector(REALSXP,4));
pc++;
REAL(dvec)[0] = oExt.MinX;
REAL(dvec)[1] = oExt.MinY;
REAL(dvec)[2] = oExt.MaxX;
REAL(dvec)[3] = oExt.MaxY;
SET_VECTOR_ELT(ans,4,dvec);
}
uninstallErrorHandlerAndTriggerError();
PROTECT(itemnames=allocVector(STRSXP,nFields));
pc++;
PROTECT(itemtype=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemwidth=allocVector(INTSXP,nFields));
pc++;
// try List types
PROTECT(itemlistmaxcount=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemTypeNames=allocVector(STRSXP,nFields));
pc++;
int listFieldCount=0;
installErrorHandler();
for(iField=0; iField<nFields; iField++) {
OGRFieldDefn *poField = poDefn->GetFieldDefn(iField);
SET_STRING_ELT(itemnames,iField,mkChar(poField->GetNameRef()));
INTEGER(itemtype)[iField]=poField->GetType();
if (INTEGER(itemtype)[iField] == OFTIntegerList ||
INTEGER(itemtype)[iField] == OFTRealList ||
INTEGER(itemtype)[iField] == OFTStringList) listFieldCount++;
INTEGER(itemwidth)[iField]=poField->GetWidth();
SET_STRING_ELT(itemTypeNames,iField,mkChar(poField->GetFieldTypeName(
poField->GetType())));
INTEGER(itemlistmaxcount)[iField] = 0;
}
uninstallErrorHandlerAndTriggerError();
PROTECT(vec3=allocVector(INTSXP,1));
pc++;
INTEGER(vec3)[0]=listFieldCount;
SET_VECTOR_ELT(ans,5,vec3);
PROTECT(itemlist=allocVector(VECSXP,5));
pc++;
SET_VECTOR_ELT(itemlist,0,itemnames);
SET_VECTOR_ELT(itemlist,1,itemtype);
SET_VECTOR_ELT(itemlist,2,itemwidth);
SET_VECTOR_ELT(itemlist,3,itemTypeNames);
// try List types
if (listFieldCount > 0) {
poLayer->ResetReading();
OGRFeature* poFeature;
nCount = (int *) R_alloc((size_t) nFields, sizeof(int));
for (iField=0; iField<nFields; iField++) nCount[iField] = 0;
installErrorHandler();
OGRField* psField;
while( (poFeature = poLayer->GetNextFeature()) != NULL ) {
for(iField=0; iField<nFields; iField++) {
示例5: paintMap
//.........这里部分代码省略.........
//if(iwidth<0.06)
// iwidth=0.06;
if(iwidth == 0.0015){
pen.setWidth(pwidth);
}
else
{
pen.setWidth(iwidth);
}
//std::cerr<<pwidth<<" "<<iwidth<<"\n";
pen.setColor(bordercolor);
brush.setStyle(SolidPattern);
brush.setColor(fillcolor);
font= new WFont();
font->setSize(WLength(labelpercentage*gWidth*widthFactor));
painter.setFont(*font);
painter.setPen(pen);
painter.setBrush(brush);
WPainterPath path;
poLayer->ResetReading();
OGRPoint *centroid = new OGRPoint();
char label[100];
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
centroid->empty();
label[0]=0;
if(labelindex>0)
{
OGRFeatureDefn *PointFDefn = poLayer->GetLayerDefn();
OGRFieldDefn *PointFieldDefn = PointFDefn->GetFieldDefn(labelindex-1);
if( PointFieldDefn->GetType() == OFTInteger )
sprintf(label, "%d", poFeature->GetFieldAsInteger(labelindex-1) );
else if( PointFieldDefn->GetType() == OFTReal )
sprintf(label, "%.3f", poFeature->GetFieldAsDouble(labelindex-1) );
else if( PointFieldDefn->GetType() == OFTString )
sprintf(label, "%s", poFeature->GetFieldAsString(labelindex-1) );
else
sprintf(label, "%s", poFeature->GetFieldAsString(labelindex-1) );
}
OGRGeometry *poGeometry;
poGeometry = poFeature->GetGeometryRef();
if( poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
{
OGRPoint *poPoint = (OGRPoint *) poGeometry;
double x = poPoint->getX();
double y = poPoint->getY();
//painter.drawPoint(x/scaleFactor,y/scaleFactor);
painter.drawEllipse(x/scaleFactor-0.005*gWidth*widthFactor,y/scaleFactor-0.005*gWidth*widthFactor,0.01*gWidth*widthFactor,0.01*gWidth*widthFactor);
poGeometry->Centroid(centroid);
} //end wkbpoint
else if( poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbLineString )
{
OGRLineString *poPoint = (OGRLineString *) poGeometry;
for(int i=0;i<poPoint->getNumPoints();i++)
{
double x=poPoint->getX(i) ;
double y = poPoint->getY(i);
x/=scaleFactor; y/=scaleFactor;
示例6: init
//.........这里部分代码省略.........
else
{
std::ostringstream s;
s << "OGR Plugin: Cannot determine extent for layer '" << layer->GetLayerDefn()->GetName() << "'. Please provide a manual extent string (minx,miny,maxx,maxy).";
throw datasource_exception(s.str());
}
}
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
}
// scan for index file
// TODO - layer names don't match dataset name, so this will break for
// any layer types of ogr than shapefiles, etc
// fix here and in ogrindex
size_t breakpoint = dataset_name_.find_last_of(".");
if (breakpoint == std::string::npos)
{
breakpoint = dataset_name_.length();
}
index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex";
#if defined (_WINDOWS)
std::ifstream index_file(mapnik::utf8_to_utf16(index_name_), std::ios::in | std::ios::binary);
#else
std::ifstream index_file(index_name_.c_str(), std::ios::in | std::ios::binary);
#endif
if (index_file)
{
indexed_ = true;
index_file.close();
}
#if 0
// TODO - enable this warning once the ogrindex tool is a bit more stable/mature
else
{
MAPNIK_LOG_DEBUG(ogr) << "ogr_datasource: no ogrindex file found for " << dataset_name_
<< ", use the 'ogrindex' program to build an index for faster rendering";
}
#endif
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::init(get_column_description)");
#endif
// deal with attributes descriptions
OGRFeatureDefn* def = layer->GetLayerDefn();
if (def != 0)
{
const int fld_count = def->GetFieldCount();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = def->GetFieldDefn(i);
const std::string fld_name = fld->GetNameRef();
const OGRFieldType type_oid = fld->GetType();
switch (type_oid)
{
case OFTInteger:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Integer));
break;
case OFTReal:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Double));
break;
case OFTString:
case OFTWideString: // deprecated
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String));
break;
case OFTBinary:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object));
break;
case OFTIntegerList:
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
MAPNIK_LOG_WARN(ogr) << "ogr_datasource: Unhandled type_oid=" << type_oid;
break;
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object));
MAPNIK_LOG_WARN(ogr) << "ogr_datasource: Unhandled type_oid=" << type_oid;
break;
}
}
}
mapnik::parameters & extra_params = desc_.get_extra_parameters();
OGRSpatialReference * srs_ref = layer->GetSpatialRef();
char * srs_output = NULL;
if (srs_ref && srs_ref->exportToProj4( &srs_output ) == OGRERR_NONE ) {
extra_params["proj4"] = mapnik::util::trim_copy(srs_output);
}
CPLFree(srs_output);
}
示例7: main
//.........这里部分代码省略.........
{
poFeatureDefn = poLayer->GetLayerDefn()->Clone();
}
else if ( !accept_different_schemas )
{
OGRFeatureDefn* poFeatureDefnCur = poLayer->GetLayerDefn();
assert(NULL != poFeatureDefnCur);
int fieldCount = poFeatureDefnCur->GetFieldCount();
if( fieldCount != poFeatureDefn->GetFieldCount())
{
fprintf( stderr, "Number of attributes of layer %s of %s does not match ... skipping it.\n",
poLayer->GetLayerDefn()->GetName(), papszArgv[nFirstSourceDataset]);
if (bFirstWarningForNonMatchingAttributes)
{
fprintf( stderr, "Note : you can override this behaviour with -accept_different_schemas option\n"
"but this may result in a tileindex incompatible with MapServer\n");
bFirstWarningForNonMatchingAttributes = FALSE;
}
continue;
}
int bSkip = FALSE;
for( int fn = 0; fn < poFeatureDefnCur->GetFieldCount(); fn++ )
{
OGRFieldDefn* poField = poFeatureDefn->GetFieldDefn(fn);
OGRFieldDefn* poFieldCur = poFeatureDefnCur->GetFieldDefn(fn);
/* XXX - Should those pointers be checked against NULL? */
assert(NULL != poField);
assert(NULL != poFieldCur);
if( poField->GetType() != poFieldCur->GetType()
|| poField->GetWidth() != poFieldCur->GetWidth()
|| poField->GetPrecision() != poFieldCur->GetPrecision()
|| !EQUAL( poField->GetNameRef(), poFieldCur->GetNameRef() ) )
{
fprintf( stderr, "Schema of attributes of layer %s of %s does not match ... skipping it.\n",
poLayer->GetLayerDefn()->GetName(), papszArgv[nFirstSourceDataset]);
if (bFirstWarningForNonMatchingAttributes)
{
fprintf( stderr, "Note : you can override this behaviour with -accept_different_schemas option\n"
"but this may result in a tileindex incompatible with MapServer\n");
bFirstWarningForNonMatchingAttributes = FALSE;
}
bSkip = TRUE;
break;
}
}
if (bSkip)
continue;
}
/* -------------------------------------------------------------------- */
/* Get layer extents, and create a corresponding polygon */
/* geometry. */
/* -------------------------------------------------------------------- */
OGREnvelope sExtents;
OGRPolygon oRegion;
OGRLinearRing oRing;
if( poLayer->GetExtent( &sExtents, TRUE ) != OGRERR_NONE )
{
示例8: bind
//.........这里部分代码省略.........
}
if (!found) {
s << "None (no layers were found in dataset)";
}
throw datasource_exception(s.str());
}
if (!layer_)
{
std::string s("OGR Plugin: ");
if (layer_by_name) s += "cannot find layer by name '" + *layer_by_name;
else if (layer_by_index) s += "cannot find layer by index number '" + *layer_by_index;
s += "' in dataset '" + dataset_name_ + "'";
throw datasource_exception(s);
}
// initialize envelope
OGREnvelope envelope;
layer_->GetExtent (&envelope);
extent_.init (envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
// scan for index file
// TODO - layer names don't match dataset name, so this will break for
// any layer types of ogr than shapefiles, etc
// fix here and in ogrindex
size_t breakpoint = dataset_name_.find_last_of (".");
if (breakpoint == std::string::npos) breakpoint = dataset_name_.length();
index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex";
std::ifstream index_file (index_name_.c_str(), std::ios::in | std::ios::binary);
if (index_file)
{
indexed_=true;
index_file.close();
}
// enable this warning once the ogrindex tool is a bit more stable/mature
//else
/*{
std::clog << "### Notice: no ogrindex file found for " + dataset_name_ + ", use the 'ogrindex' program to build an index for faster rendering\n";
}*/
// deal with attributes descriptions
OGRFeatureDefn* def = layer_->GetLayerDefn ();
if (def != 0)
{
int fld_count = def->GetFieldCount ();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = def->GetFieldDefn (i);
std::string fld_name = fld->GetNameRef ();
OGRFieldType type_oid = fld->GetType ();
switch (type_oid)
{
case OFTInteger:
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
break;
case OFTReal:
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
break;
case OFTString:
case OFTWideString: // deprecated
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
break;
case OFTBinary:
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
break;
case OFTIntegerList:
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
#ifdef MAPNIK_DEBUG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
#endif
break;
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
#ifdef MAPNIK_DEBUG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
#endif
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
break;
default: // unknown
#ifdef MAPNIK_DEBUG
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
#endif
break;
}
}
}
is_bound_ = true;
}
示例9: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, int bVerbose )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poLayer->GetName() );
if( bVerbose )
{
int nGeomFieldCount =
poLayer->GetLayerDefn()->GetGeomFieldCount();
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
printf( "Geometry (%s): %s\n", poGFldDefn->GetNameRef(),
OGRGeometryTypeToName( poGFldDefn->GetType() ) );
}
}
else
{
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poLayer->GetGeomType() ) );
}
printf( "Feature Count: " CPL_FRMT_GIB "\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
if (poLayer->GetExtent(iGeom, &oExt, TRUE) == OGRERR_NONE)
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
CPLprintf("Extent (%s): (%f, %f) - (%f, %f)\n",
poGFldDefn->GetNameRef(),
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
}
}
else if ( poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
CPLprintf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
char *pszWKT;
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
OGRSpatialReference* poSRS = poGFldDefn->GetSpatialRef();
if( poSRS == nullptr )
pszWKT = CPLStrdup( "(unknown)" );
else
{
poSRS->exportToPrettyWkt( &pszWKT );
}
printf( "SRS WKT (%s):\n%s\n",
poGFldDefn->GetNameRef(), pszWKT );
CPLFree( pszWKT );
}
}
else
{
if( poLayer->GetSpatialRef() == nullptr )
pszWKT = CPLStrdup( "(unknown)" );
else
{
poLayer->GetSpatialRef()->exportToPrettyWkt( &pszWKT );
}
printf( "Layer SRS WKT:\n%s\n", pszWKT );
CPLFree( pszWKT );
}
if( strlen(poLayer->GetFIDColumn()) > 0 )
printf( "FID Column = %s\n",
poLayer->GetFIDColumn() );
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
if( nGeomFieldCount == 1 &&
EQUAL(poGFldDefn->GetNameRef(), "") && poGFldDefn->IsNullable() )
break;
//.........这里部分代码省略.........
示例10: ExecuteSQL
//.........这里部分代码省略.........
if( oSelect.join_count == 0 && oSelect.poOtherSelect == NULL &&
oSelect.table_count == 1 && oSelect.order_specs == 0 &&
oSelect.query_mode != SWQM_DISTINCT_LIST )
{
OGROpenFileGDBLayer* poLayer =
(OGROpenFileGDBLayer*)GetLayerByName( oSelect.table_defs[0].table_name);
if( poLayer )
{
OGRMemLayer* poMemLayer = NULL;
int i;
for(i = 0; i < oSelect.result_columns; i ++ )
{
swq_col_func col_func = oSelect.column_defs[i].col_func;
if( !(col_func == SWQCF_MIN || col_func == SWQCF_MAX ||
col_func == SWQCF_COUNT || col_func == SWQCF_AVG ||
col_func == SWQCF_SUM) )
break;
if( oSelect.column_defs[i].field_name == NULL )
break;
if( oSelect.column_defs[i].distinct_flag )
break;
if( oSelect.column_defs[i].target_type != SWQ_OTHER )
break;
int idx = poLayer->GetLayerDefn()->GetFieldIndex(
oSelect.column_defs[i].field_name);
if( idx < 0 )
break;
OGRFieldDefn* poFieldDefn = poLayer->GetLayerDefn()->GetFieldDefn(idx);
if( col_func == SWQCF_SUM && poFieldDefn->GetType() == OFTDateTime )
break;
int eOutOGRType = -1;
int nCount = 0;
double dfSum = 0.0;
const OGRField* psField = NULL;
OGRField sField;
if( col_func == SWQCF_MIN || col_func == SWQCF_MAX )
{
psField = poLayer->GetMinMaxValue(
poFieldDefn, col_func == SWQCF_MIN, eOutOGRType);
if( eOutOGRType < 0 )
break;
}
else
{
double dfMin = 0.0, dfMax = 0.0;
if( !poLayer->GetMinMaxSumCount(poFieldDefn, dfMin, dfMax,
dfSum, nCount) )
break;
psField = &sField;
if( col_func == SWQCF_AVG )
{
if( nCount == 0 )
{
eOutOGRType = OFTReal;
psField = NULL;
}
else
{
if( poFieldDefn->GetType() == OFTDateTime )
{
示例11: if
//.........这里部分代码省略.........
if( strstr(poFD->pszFieldName,poFD->pszPathToSequence) != NULL )
pszPathFromSubSeq =
strstr(poFD->pszFieldName,poFD->pszPathToSequence)
+ strlen(poFD->pszPathToSequence) + 1;
else
continue;
/* -------------------------------------------------------------------- */
/* Get the sequence out of which this variable will be collected. */
/* -------------------------------------------------------------------- */
BaseType *poFieldVar = seq->var_value( iSubSeq,
poFD->pszPathToSequence );
Sequence *poSubSeq;
int nSubSeqCount;
if( poFieldVar == NULL )
continue;
poSubSeq = dynamic_cast<Sequence *>( poFieldVar );
if( poSubSeq == NULL )
continue;
nSubSeqCount = poSubSeq->number_of_rows();
/* -------------------------------------------------------------------- */
/* Allocate array to put values into. */
/* -------------------------------------------------------------------- */
OGRFieldDefn *poOFD = poFeature->GetFieldDefnRef( iField );
int *panIntList = NULL;
double *padfDblList = NULL;
char **papszStrList = NULL;
if( poOFD->GetType() == OFTIntegerList )
{
panIntList = (int *) CPLCalloc(sizeof(int),nSubSeqCount);
}
else if( poOFD->GetType() == OFTRealList )
{
padfDblList = (double *) CPLCalloc(sizeof(double),nSubSeqCount);
}
else if( poOFD->GetType() == OFTStringList )
{
papszStrList = (char **) CPLCalloc(sizeof(char*),nSubSeqCount+1);
}
else
continue;
/* -------------------------------------------------------------------- */
/* Loop, fetching subsequence values. */
/* -------------------------------------------------------------------- */
int iSubIndex;
for( iSubIndex = 0; iSubIndex < nSubSeqCount; iSubIndex++ )
{
poFieldVar = poSubSeq->var_value( iSubIndex, pszPathFromSubSeq );
if( poFieldVar == NULL )
continue;
switch( poFieldVar->type() )
{
case dods_byte_c:
{
signed char byVal;
void *pValPtr = &byVal;
示例12: bind
//.........这里部分代码省略.........
s << "cannot find layer by index number '" << *layer_by_index;
}
else if (layer_by_sql)
{
s << "cannot find layer by sql query '" << *layer_by_sql;
}
s << "' in dataset '" << dataset_name_ << "'";
throw datasource_exception(s.str());
}
// work with real OGR layer
OGRLayer* layer = layer_.layer();
// initialize envelope
OGREnvelope envelope;
layer->GetExtent(&envelope);
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
// scan for index file
// TODO - layer names don't match dataset name, so this will break for
// any layer types of ogr than shapefiles, etc
// fix here and in ogrindex
size_t breakpoint = dataset_name_.find_last_of(".");
if (breakpoint == std::string::npos)
{
breakpoint = dataset_name_.length();
}
index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex";
std::ifstream index_file(index_name_.c_str(), std::ios::in | std::ios::binary);
if (index_file)
{
indexed_ = true;
index_file.close();
}
#if 0
// TODO - enable this warning once the ogrindex tool is a bit more stable/mature
else
{
MAPNIK_LOG_DEBUG(ogr) << "ogr_datasource: no ogrindex file found for " << dataset_name_
<< ", use the 'ogrindex' program to build an index for faster rendering";
}
#endif
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::bind(get_column_description)");
#endif
// deal with attributes descriptions
OGRFeatureDefn* def = layer->GetLayerDefn();
if (def != 0)
{
const int fld_count = def->GetFieldCount();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = def->GetFieldDefn(i);
const std::string fld_name = fld->GetNameRef();
const OGRFieldType type_oid = fld->GetType();
switch (type_oid)
{
case OFTInteger:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Integer));
break;
case OFTReal:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Double));
break;
case OFTString:
case OFTWideString: // deprecated
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String));
break;
case OFTBinary:
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object));
break;
case OFTIntegerList:
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
MAPNIK_LOG_WARN(ogr) << "ogr_datasource: Unhandled type_oid=" << type_oid;
break;
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object));
MAPNIK_LOG_WARN(ogr) << "ogr_datasource: Unhandled type_oid=" << type_oid;
break;
}
}
}
is_bound_ = true;
}
示例13: if
CPLXMLNode *OGRFMELayerCached::SerializeToXML()
{
CPLXMLNode *psLayer;
char szGeomType[64];
psLayer = CPLCreateXMLNode( NULL, CXT_Element, "OGRLayer" );
/* -------------------------------------------------------------------- */
/* Handle various layer values. */
/* -------------------------------------------------------------------- */
CPLCreateXMLElementAndValue( psLayer, "Name", poFeatureDefn->GetName());
sprintf( szGeomType, "%d", (int) poFeatureDefn->GetGeomType() );
CPLCreateXMLElementAndValue( psLayer, "GeomType", szGeomType );
CPLCreateXMLElementAndValue( psLayer, "SpatialCacheName",
pszIndexBase );
/* -------------------------------------------------------------------- */
/* Handle spatial reference if available. */
/* -------------------------------------------------------------------- */
if( GetSpatialRef() != NULL )
{
char *pszWKT = NULL;
OGRSpatialReference *poSRS = GetSpatialRef();
poSRS->exportToWkt( &pszWKT );
if( pszWKT != NULL )
{
CPLCreateXMLElementAndValue( psLayer, "SRS", pszWKT );
CPLFree( pszWKT );
}
}
/* -------------------------------------------------------------------- */
/* Handle extents if available. */
/* -------------------------------------------------------------------- */
OGREnvelope sEnvelope;
if( GetExtent( &sEnvelope, FALSE ) == OGRERR_NONE )
{
char szExtent[512];
sprintf( szExtent, "%24.15E,%24.15E,%24.15E,%24.15E",
sEnvelope.MinX, sEnvelope.MinY,
sEnvelope.MaxX, sEnvelope.MaxY );
CPLCreateXMLElementAndValue( psLayer, "Extent", szExtent );
}
/* -------------------------------------------------------------------- */
/* Emit the field schemas. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psSchema = CPLCreateXMLNode( psLayer, CXT_Element, "Schema" );
for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDef = poFeatureDefn->GetFieldDefn( iField );
const char *pszType;
char szWidth[32], szPrecision[32];
CPLXMLNode *psXMLFD;
sprintf( szWidth, "%d", poFieldDef->GetWidth() );
sprintf( szPrecision, "%d", poFieldDef->GetPrecision() );
if( poFieldDef->GetType() == OFTInteger )
pszType = "Integer";
else if( poFieldDef->GetType() == OFTIntegerList )
pszType = "IntegerList";
else if( poFieldDef->GetType() == OFTReal )
pszType = "Real";
else if( poFieldDef->GetType() == OFTRealList )
pszType = "RealList";
else if( poFieldDef->GetType() == OFTString )
pszType = "String";
else if( poFieldDef->GetType() == OFTStringList )
pszType = "StringList";
else if( poFieldDef->GetType() == OFTBinary )
pszType = "Binary";
else
pszType = "Unsupported";
psXMLFD = CPLCreateXMLNode( psSchema, CXT_Element, "OGRFieldDefn" );
CPLCreateXMLElementAndValue( psXMLFD, "Name",poFieldDef->GetNameRef());
CPLCreateXMLElementAndValue( psXMLFD, "Type", pszType );
CPLCreateXMLElementAndValue( psXMLFD, "Width", szWidth );
CPLCreateXMLElementAndValue( psXMLFD, "Precision", szPrecision );
}
return psLayer;
}
示例14: Compile
OGRErr OGRFeatureQuery::Compile( OGRFeatureDefn *poDefn,
const char * pszExpression )
{
/* -------------------------------------------------------------------- */
/* Clear any existing expression. */
/* -------------------------------------------------------------------- */
if( pSWQExpr != NULL )
{
delete (swq_expr_node *) pSWQExpr;
pSWQExpr = NULL;
}
/* -------------------------------------------------------------------- */
/* Build list of fields. */
/* -------------------------------------------------------------------- */
char **papszFieldNames;
swq_field_type *paeFieldTypes;
int iField;
int nFieldCount = poDefn->GetFieldCount() + SPECIAL_FIELD_COUNT;
papszFieldNames = (char **)
CPLMalloc(sizeof(char *) * nFieldCount );
paeFieldTypes = (swq_field_type *)
CPLMalloc(sizeof(swq_field_type) * nFieldCount );
for( iField = 0; iField < poDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iField );
papszFieldNames[iField] = (char *) poField->GetNameRef();
switch( poField->GetType() )
{
case OFTInteger:
paeFieldTypes[iField] = SWQ_INTEGER;
break;
case OFTReal:
paeFieldTypes[iField] = SWQ_FLOAT;
break;
case OFTString:
paeFieldTypes[iField] = SWQ_STRING;
break;
case OFTDate:
case OFTTime:
case OFTDateTime:
paeFieldTypes[iField] = SWQ_TIMESTAMP;
break;
default:
paeFieldTypes[iField] = SWQ_OTHER;
break;
}
}
iField = 0;
while (iField < SPECIAL_FIELD_COUNT)
{
papszFieldNames[poDefn->GetFieldCount() + iField] = (char *) SpecialFieldNames[iField];
paeFieldTypes[poDefn->GetFieldCount() + iField] = SpecialFieldTypes[iField];
++iField;
}
/* -------------------------------------------------------------------- */
/* Try to parse. */
/* -------------------------------------------------------------------- */
OGRErr eErr = OGRERR_NONE;
CPLErr eCPLErr;
poTargetDefn = poDefn;
eCPLErr = swq_expr_compile( pszExpression, nFieldCount,
papszFieldNames, paeFieldTypes,
(swq_expr_node **) &pSWQExpr );
if( eCPLErr != CE_None )
{
eErr = OGRERR_CORRUPT_DATA;
pSWQExpr = NULL;
}
CPLFree( papszFieldNames );
CPLFree( paeFieldTypes );
return eErr;
}
示例15: InsertHeader
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* Emit initial stuff for a feature type. */
/* -------------------------------------------------------------------- */
VSIFPrintf(
fpSchema,
"<xs:element name=\"%s\" type=\"%s:%s_Type\" substitutionGroup=\"gml:_Feature\"/>\n",
poFDefn->GetName(), pszPrefix, poFDefn->GetName() );
VSIFPrintf(
fpSchema,
"<xs:complexType name=\"%s_Type\">\n"
" <xs:complexContent>\n"
" <xs:extension base=\"gml:AbstractFeatureType\">\n"
" <xs:sequence>\n",
poFDefn->GetName() );
/* -------------------------------------------------------------------- */
/* Define the geometry attribute. For now I always use the */
/* generic geometry type, but eventually we should express */
/* particulars if available. */
/* -------------------------------------------------------------------- */
VSIFPrintf(
fpSchema,
"<xs:element name=\"geometryProperty\" type=\"gml:GeometryPropertyType\" nillable=\"true\" minOccurs=\"1\" maxOccurs=\"1\"/>\n" );
/* -------------------------------------------------------------------- */
/* Emit each of the attributes. */
/* -------------------------------------------------------------------- */
for( int iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
if( poFieldDefn->GetType() == OFTInteger )
{
int nWidth;
if( poFieldDefn->GetWidth() > 0 )
nWidth = poFieldDefn->GetWidth();
else
nWidth = 16;
VSIFPrintf( fpSchema,
" <xs:element name=\"%s\" nillable=\"true\" minOccurs=\"0\" maxOccurs=\"1\">\n"
" <xs:simpleType>\n"
" <xs:restriction base=\"xs:integer\">\n"
" <xs:totalDigits value=\"%d\"/>\n"
" </xs:restriction>\n"
" </xs:simpleType>\n"
" </xs:element>\n",
poFieldDefn->GetNameRef(), nWidth );
}
else if( poFieldDefn->GetType() == OFTReal )
{
int nWidth, nDecimals;
if( poFieldDefn->GetPrecision() == 0 )
nDecimals = 0;
else
nDecimals = poFieldDefn->GetPrecision();
if( poFieldDefn->GetWidth() > 0 )
nWidth = poFieldDefn->GetWidth();
else
nWidth = 33;