当前位置: 首页>>代码示例>>C++>>正文


C++ OGRFeature::GetRawFieldRef方法代码示例

本文整理汇总了C++中OGRFeature::GetRawFieldRef方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::GetRawFieldRef方法的具体用法?C++ OGRFeature::GetRawFieldRef怎么用?C++ OGRFeature::GetRawFieldRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OGRFeature的用法示例。


在下文中一共展示了OGRFeature::GetRawFieldRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ogrInfo


//.........这里部分代码省略.........
    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++) {
                psField = poFeature->GetRawFieldRef(iField);
                if (INTEGER(itemtype)[iField] == OFTIntegerList) {
                    nCount[iField] = psField->IntegerList.nCount;
                    if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
                        INTEGER(itemlistmaxcount)[iField] = nCount[iField];
                } else if (INTEGER(itemtype)[iField] == OFTRealList) {
                    nCount[iField] = psField->RealList.nCount;
                    if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
                        INTEGER(itemlistmaxcount)[iField] = nCount[iField];
                } else if (INTEGER(itemtype)[iField] == OFTStringList) {
                    nCount[iField] = psField->StringList.nCount;
                    if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
                        INTEGER(itemlistmaxcount)[iField] = nCount[iField];
                }
            }
            OGRFeature::DestroyFeature( poFeature );
//    delete poFeature;
        }
        uninstallErrorHandlerAndTriggerError();

    }
    SET_VECTOR_ELT(itemlist,4,itemlistmaxcount);
    SET_VECTOR_ELT(ans,2,itemlist);

    UNPROTECT(pc);

    installErrorHandler();
#ifdef GDALV2
    GDALClose( poDS );
#else
    OGRDataSource::DestroyDataSource( poDS );
#endif
    uninstallErrorHandlerAndTriggerError();
//    delete poDS;
    return(ans);

}
开发者ID:rforge,项目名称:rgdal,代码行数:101,代码来源:ogrsource.cpp

示例2: 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];
//.........这里部分代码省略.........
开发者ID:rforge,项目名称:rgdal,代码行数:101,代码来源:ogrsource.cpp

示例3: main

int main(int argc, char **argv)
{
  // Get data from ogr
  OGRRegisterAll();
  std::cout << "Opening: " << argv[1] << std::endl;

  OGRDataSource *shp = OGRSFDriverRegistrar::Open(argv[1], FALSE);
  IsValid(shp, "Error opening file.");

  std::cout << "Shape contains " << shp->GetLayerCount() << " layers." << std::endl;
  OGRLayer *layer = shp->GetLayerByName(argv[2]);
  IsValid(layer, "Couldn't grab layer");

  OGRSpatialReference *srcSRS = NULL;
  srcSRS = layer->GetSpatialRef();

  // Set up writing
  const char *kDriverName = "ESRI Shapefile";
  OGRSFDriver *shpDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(kDriverName);
  IsValid(shpDriver, "Couldn't grab the shapefile driver.");

  IsValid(argv[3], "Please provide a output shp.");
  std::cout << "Writing to: " << argv[3] << std::endl;
  OGRDataSource *shpOut = shpDriver->CreateDataSource(argv[3], NULL);
  IsValid(shpOut, "Couldn't open output file");

  OGRLayer *outLayer = shpOut->CreateLayer(layer->GetName(), srcSRS, wkbMultiLineString, NULL);
  IsValid(outLayer, "Couldn't create an output layer");

  // copy over the fields from the source file
  OGRFeatureDefn *source = layer->GetLayerDefn();
  for(int i=0; i < source->GetFieldCount(); i++){
    OGRFieldDefn *field = source->GetFieldDefn(i);
    if(outLayer->CreateField(field) != OGRERR_NONE) {
      std::cout << "Couldn't make layer" << std::endl; exit(1);
    };
  }

  // Loop through features and grab the hull and put it into CGAL then
  // skeletonize the points
  OGRFeature *feature;
  int count = 0;
  while((feature = layer->GetNextFeature()) != NULL)
  {
    OGRMultiPolygon *geometry = dynamic_cast<OGRMultiPolygon *>(OGRGeometryFactory::forceToMultiPolygon(feature->GetGeometryRef()));
    IsValid(geometry, "No geometry.");

    OGRFeature *outFeature = OGRFeature::CreateFeature(outLayer->GetLayerDefn());
    IsValid(outFeature, "Couldn't make a feature.");

    for(int i=0; i < source->GetFieldCount(); i++){
      OGRField *field = feature->GetRawFieldRef(i);
      outFeature->SetField(i, field);
    }

    OGRGeometry* line = NULL;
    for(int i=0; i < geometry->getNumGeometries(); i++){
      OGRGeometry* segment = BuildMultiLine(geometry->getGeometryRef(i));
      if(segment != NULL){
        if(line == NULL) { line = new OGRLineString; }
        OGRGeometry* tmp = line->Union(segment);
        if(tmp != NULL){
          delete line;
          line = tmp;
        }
        delete segment;
      }
    }
    outFeature->SetGeometry(line);
    if(outLayer->CreateFeature(outFeature) != OGRERR_NONE){
      std::cout << "Couldn't create feature." << std::endl;
      exit(1);
    }

    // clean up
    OGRFeature::DestroyFeature(outFeature);
    std::cout << std::endl << ++count << std::endl;
  }

  // cleanup
  OGRDataSource::DestroyDataSource(shp);
  OGRDataSource::DestroyDataSource(shpOut);
  return 0;
}
开发者ID:thejefflarson,项目名称:skeletonize,代码行数:84,代码来源:skeleton.cpp


注:本文中的OGRFeature::GetRawFieldRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。