bool FeatureConnector::loadBinaryPolygons30(FeatureCoverage *fcoverage, ITable& tbl) { BinaryIlwis3Table polTable; if ( !polTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } BinaryIlwis3Table topTable; if ( !topTable.load(_odf,"top")) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } qint32 colValue = polTable.index("PolygonValue"); qint32 colTopStart = polTable.index("TopStart"); qint32 colArea = polTable.index("Area"); int nrPolygons = polTable.rows(); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; double v; for(int i = 0; i < nrPolygons; ++i) { polTable.get(i,colArea, v); if ( v < 0) continue; polTable.get(i,colTopStart,v); qint32 index = v; std::vector<std::vector<Coordinate2d>> rings; if (getRings(index, topTable, polTable, rings)) { if ( rings.size() == 0) continue; Polygon polygon; polygon.outer().resize(rings[0].size()); std::copy(rings[0].begin(), rings[0].end(), polygon.outer().begin()); for(int j = 1; j < rings.size(); ++j) { polygon.inners()[j-1].resize(rings[j].size()); std::copy(rings[j].begin(), rings[j].end(), polygon.inners()[j-1].begin()); } polTable.get(i, colValue, v); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(i)); tbl->cell(FEATUREVALUECOLUMN, i, QVariant(v)); fcoverage->newFeature({polygon}); } else { quint32 itemId = v; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({polygon}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } } } return true; }
bool FeatureConnector::loadBinaryData(Ilwis::IlwisObject *obj) { if ( obj == nullptr) return false; FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(obj); QString file = _odf->value("BaseMap", "AttributeTable"); ITable extTable; if ( file != sUNDEF) { if(!extTable.prepare(file)){ kernel()->issues()->log(file,TR(ERR_NO_INITIALIZED_1).arg(file),IssueObject::itWarning); return false; } } bool ok = false; if (fcoverage->featureTypes() == itPOINT) ok = loadBinaryPoints(fcoverage); else if (fcoverage->featureTypes() == itLINE) ok = loadBinarySegments(fcoverage); else if (fcoverage->featureTypes() == itPOLYGON) ok = loadBinaryPolygons(fcoverage); if ( ok && extTable.isValid()) { ITable attTbl = fcoverage->attributeTable(); quint32 keyIndex = attTbl->columnIndex(COVERAGEKEYCOLUMN); for(quint32 rowExt=0; rowExt < extTable->records(); ++rowExt) { vector<QVariant> rec = extTable->record(rowExt); for(quint32 rowAtt = 0; rowAtt < attTbl->records(); ++rowAtt ) { if ( attTbl->cell(keyIndex, rowAtt) == rowExt + 1) { attTbl->record(rowAtt,rec); } } } } return ok; }
bool FeatureConnector::loadBinaryPolygons37(FeatureCoverage *fcoverage, ITable& tbl) { QString datafile = _odf->value("PolygonMapStore","DataPol"); datafile = context()->workingCatalog()->filesystemLocation().toLocalFile() + "/" + datafile; QFile file(datafile); if (!file.exists()){ kernel()->issues()->log(TR(ERR_MISSING_DATA_FILE_1).arg(file.fileName())); return false; } if(!file.open(QIODevice::ReadOnly )){ kernel()->issues()->log(TR(ERR_COULD_NOT_OPEN_READING_1).arg(file.fileName())); return false; } QDataStream stream(&file); int nrPolygons = fcoverage->featureCount(itPOLYGON); SPAttributeRecord record( new AttributeRecord(tbl,FEATUREIDCOLUMN)); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; for(int j=0; j < nrPolygons; ++j) { Polygon pol; readRing(stream, pol.outer()); double value; quint32 numberOfHoles; stream.readRawData((char *)&value, 8); stream.readRawData((char *)&numberOfHoles, 4); pol.inners().resize(numberOfHoles); for(quint32 i=0; i< numberOfHoles;++i) readRing(stream, pol.inners()[i]); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, j, QVariant(j)); tbl->cell(FEATUREVALUECOLUMN, j, QVariant(value)); SPFeatureI feature = fcoverage->newFeature({pol}); tbl->cell(FEATUREIDCOLUMN, j, QVariant(feature->featureid())); } else { quint32 itemId = value; tbl->cell(COVERAGEKEYCOLUMN, j, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({pol}); tbl->cell(FEATUREIDCOLUMN, j, QVariant(feature->featureid())); } } file.close(); return true; }
bool FeatureConnector::loadBinarySegments(FeatureCoverage *fcoverage) { BinaryIlwis3Table mpsTable; if ( !mpsTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } int colCoords = mpsTable.index("Coords"); int colItemId = mpsTable.index("SegmentValue"); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; ITable tbl = fcoverage->attributeTable(); // if ( isNumeric) // in other case nr of record already has been set as it is based on a real table // tbl->setRows(mpsTable.rows()); double value; for(quint32 i= 0; i < mpsTable.rows(); ++i) { std::vector<Coordinate > coords; mpsTable.get(i,colCoords,coords); Line2D<Coordinate2d > line; line.resize(coords.size()); std::copy(coords.begin(), coords.end(), line.begin()); mpsTable.get(i, colItemId,value); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(i)); tbl->cell(FEATUREVALUECOLUMN, i, QVariant(value)); SPFeatureI feature = fcoverage->newFeature({line}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } else { quint32 itemId = value; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({line}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } } return true; }
bool FeatureConnector::loadBinaryPoints(FeatureCoverage *fcoverage) { BinaryIlwis3Table mppTable; if ( !mppTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } // two cases; the old case; 2 columns for x and y. and the new case one column for coord int coordColumnX = mppTable.index("x"); int coordColumnY = mppTable.index("y"); int coordColumn = mppTable.index("Coordinate"); int colItemId = mppTable.index("Name"); ITable tbl = fcoverage->attributeTable(); bool newCase = coordColumnX == iUNDEF; for(quint32 i= 0; i < mppTable.rows(); ++i) { Coordinate c; double itemIdT; if ( newCase) { mppTable.get(i, coordColumn, c); } else { double x,y; mppTable.get(i, coordColumnX, x); mppTable.get(i, coordColumnY, y); c = Coordinate(x,y); } mppTable.get(i, colItemId,itemIdT); quint32 itemId = itemIdT; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({c}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } return true; }
bool PercentileFilterStretch::execute(ExecutionContext *ctx, SymbolTable& symTable) { if (_prepState == sNOTPREPARED) if((_prepState = prepare(ctx,symTable)) != sPREPARED) return false; IRasterCoverage outputRaster = _outputObj.as<RasterCoverage>(); IRasterCoverage inputRaster = _inputObj.as<RasterCoverage>(); IRasterCoverage zoneRaster = _inputZones.as<RasterCoverage>(); ITable low = _lowPercentile.as<Table>(); ITable high = _highPercentile.as<Table>(); PixelIterator iterIn(inputRaster, BoundingBox(), PixelIterator::fZXY); PixelIterator iterZone(zoneRaster, BoundingBox(), PixelIterator::fXYZ); // only one layer so Z is irrelevant PixelIterator iterOut(outputRaster, BoundingBox(), PixelIterator::fZXY); PixelIterator inEnd = iterIn.end(); _nb = inputRaster->size().zsize(); int rows = inputRaster->size().xsize(); int cols = inputRaster->size().ysize(); std::vector<double> slice(_nb); std::vector<int> percentage(_nb); int totalRows = low->recordCount(); // same as high->recordCount() int totalCols = low->columnCount(); // same as high->columnCount() std::vector<double> lowtab(low->columnCount() * low->recordCount()); std::vector<double> hightab(high->columnCount() * high->recordCount()); for (int row = 0; row < totalRows; ++row) for (int col = 0; col < totalCols; ++col) { // Let the first column in the percentile table match the start of time series int actCol = (col + totalCols - _startDekad) % totalCols; lowtab[actCol + row * totalCols] = low->cell(col, row).toDouble(); hightab[actCol + row * totalCols] = high->cell(col, row).toDouble(); } // timeseries are assumed to be 10 day periods. int pixCount = 0; while (iterIn != inEnd) { trq()->update(pixCount++); // get the time slice at the current location std::copy(iterIn, iterIn + _nb, slice.begin()); // get the zone at the current location double dzone = *iterZone; // row index into low and high percentile tables if (dzone == rUNDEF) { // for out of area locations set to zero percent std::fill(percentage.begin(), percentage.end(), 0); } else { int zone = (long) dzone; std::vector<double>::const_iterator liter = lowtab.begin() + zone * totalCols; std::vector<double>::const_iterator hiter = hightab.begin() + zone * totalCols; std::vector<int>::iterator piter = percentage.begin(); for (std::vector<double>::const_iterator siter = slice.begin(); siter != slice.end(); siter++) { *piter = std::max(0, std::min(100, int(100.0 * (*hiter - *siter) / (*hiter - *liter)))); if (*piter <= 5) *piter = 0; else if (*piter <= 10) *piter = 10; piter++; liter++; hiter++; } } std::copy(percentage.begin(), percentage.end(), iterOut); iterIn += _nb; iterOut += _nb; iterZone += 1; } trq()->update(rows * cols); trq()->inform("\nWriting...\n"); trq()->stop(); bool resource = true; if ( resource && ctx != 0) { QVariant value; value.setValue<IRasterCoverage>(outputRaster); ctx->setOutput(symTable, value, outputRaster->name(), itRASTER, outputRaster->resource() ); } return resource; }