mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[MDAL] update to 0.1.5, improve speed
This commit is contained in:
parent
27c670e78d
commit
967893a637
8
external/mdal/frmts/mdal_2dm.cpp
vendored
8
external/mdal/frmts/mdal_2dm.cpp
vendored
@ -148,7 +148,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
|
||||
{
|
||||
if ( startsWith( line, "E4Q" ) )
|
||||
{
|
||||
chunks = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
chunks = split( line, ' ' );
|
||||
assert( faceIndex < faceCount );
|
||||
|
||||
Face &face = faces[faceIndex];
|
||||
@ -161,7 +161,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
|
||||
}
|
||||
else if ( startsWith( line, "E3T" ) )
|
||||
{
|
||||
chunks = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
chunks = split( line, ' ' );
|
||||
assert( faceIndex < faceCount );
|
||||
|
||||
Face &face = faces[faceIndex];
|
||||
@ -181,7 +181,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
|
||||
startsWith( line, "E9Q" ) )
|
||||
{
|
||||
// We do not yet support these elements
|
||||
chunks = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
chunks = split( line, ' ' );
|
||||
assert( faceIndex < faceCount );
|
||||
|
||||
//size_t elemID = toSizeT( chunks[1] );
|
||||
@ -191,7 +191,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
|
||||
}
|
||||
else if ( startsWith( line, "ND" ) )
|
||||
{
|
||||
chunks = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
chunks = split( line, ' ' );
|
||||
size_t nodeID = toSizeT( chunks[1] ) - 1; // 2dm is numbered from 1
|
||||
_parse_vertex_id_gaps( vertexIDtoIndex, vertexIndex, nodeID, status );
|
||||
assert( vertexIndex < vertexCount );
|
||||
|
8
external/mdal/frmts/mdal_ascii_dat.cpp
vendored
8
external/mdal/frmts/mdal_ascii_dat.cpp
vendored
@ -95,7 +95,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
|
||||
line = MDAL::trim( line );
|
||||
|
||||
// Split to tokens
|
||||
std::vector<std::string> items = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> items = split( line, ' ' );
|
||||
if ( items.size() < 1 )
|
||||
continue; // empty line?? let's skip it
|
||||
|
||||
@ -159,7 +159,7 @@ void MDAL::DriverAsciiDat::loadNewFormat( std::ifstream &in,
|
||||
line = MDAL::trim( line );
|
||||
|
||||
// Split to tokens
|
||||
std::vector<std::string> items = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> items = split( line, ' ' );
|
||||
if ( items.size() < 1 )
|
||||
continue; // empty line?? let's skip it
|
||||
|
||||
@ -320,7 +320,7 @@ void MDAL::DriverAsciiDat::readVertexTimestep(
|
||||
{
|
||||
std::string line;
|
||||
std::getline( stream, line );
|
||||
std::vector<std::string> tsItems = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> tsItems = split( line, ' ' );
|
||||
|
||||
size_t index;
|
||||
if ( m2dm )
|
||||
@ -374,7 +374,7 @@ void MDAL::DriverAsciiDat::readFaceTimestep(
|
||||
{
|
||||
std::string line;
|
||||
std::getline( stream, line );
|
||||
std::vector<std::string> tsItems = split( line, " ", SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> tsItems = split( line, ' ' );
|
||||
|
||||
if ( isVector )
|
||||
{
|
||||
|
12
external/mdal/frmts/mdal_flo2d.cpp
vendored
12
external/mdal/frmts/mdal_flo2d.cpp
vendored
@ -109,7 +109,7 @@ void MDAL::DriverFlo2D::parseCADPTSFile( const std::string &datFileName, std::ve
|
||||
// CADPTS.DAT - COORDINATES OF CELL CENTERS (ELEM NUM, X, Y)
|
||||
while ( std::getline( cadptsStream, line ) )
|
||||
{
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() != 3 )
|
||||
{
|
||||
throw MDAL_Status::Err_UnknownFormat;
|
||||
@ -140,7 +140,7 @@ void MDAL::DriverFlo2D::parseFPLAINFile( std::vector<double> &elevations,
|
||||
|
||||
while ( std::getline( fplainStream, line ) )
|
||||
{
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() != 7 )
|
||||
{
|
||||
throw MDAL_Status::Err_UnknownFormat;
|
||||
@ -220,7 +220,7 @@ void MDAL::DriverFlo2D::parseTIMDEPFile( const std::string &datFileName, const s
|
||||
|
||||
while ( std::getline( inStream, line ) )
|
||||
{
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() == 1 )
|
||||
{
|
||||
time = MDAL::toDouble( line );
|
||||
@ -303,7 +303,7 @@ void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const st
|
||||
{
|
||||
if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh;
|
||||
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() != 4 )
|
||||
{
|
||||
throw MDAL_Status::Err_UnknownFormat;
|
||||
@ -348,7 +348,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName )
|
||||
{
|
||||
if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh;
|
||||
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() != 4 )
|
||||
{
|
||||
throw MDAL_Status::Err_UnknownFormat;
|
||||
@ -378,7 +378,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName )
|
||||
{
|
||||
if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh;
|
||||
|
||||
std::vector<std::string> lineParts = MDAL::split( line, " ", MDAL::SplitBehaviour::SkipEmptyParts );
|
||||
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
|
||||
if ( lineParts.size() != 4 )
|
||||
{
|
||||
throw MDAL_Status::Err_UnknownFormat;
|
||||
|
4
external/mdal/frmts/mdal_gdal.cpp
vendored
4
external/mdal/frmts/mdal_gdal.cpp
vendored
@ -166,7 +166,7 @@ std::string MDAL::DriverGdal::GDALFileName( const std::string &fileName )
|
||||
double MDAL::DriverGdal::parseMetadataTime( const std::string &time_s )
|
||||
{
|
||||
std::string time_trimmed = MDAL::trim( time_s );
|
||||
std::vector<std::string> times = MDAL::split( time_trimmed, " ", MDAL::SkipEmptyParts );
|
||||
std::vector<std::string> times = MDAL::split( time_trimmed, ' ' );
|
||||
return MDAL::toDouble( times[0] );
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ MDAL::DriverGdal::metadata_hash MDAL::DriverGdal::parseMetadata( GDALMajorObject
|
||||
for ( int j = 0; GDALmetadata[j]; ++j )
|
||||
{
|
||||
std::string metadata_pair = GDALmetadata[j]; //KEY = VALUE
|
||||
std::vector<std::string> metadata = MDAL::split( metadata_pair, "=", MDAL::SkipEmptyParts );
|
||||
std::vector<std::string> metadata = MDAL::split( metadata_pair, '=' );
|
||||
if ( metadata.size() > 1 )
|
||||
{
|
||||
std::string key = MDAL::toLower( metadata[0] );
|
||||
|
2
external/mdal/mdal.cpp
vendored
2
external/mdal/mdal.cpp
vendored
@ -22,7 +22,7 @@ static MDAL_Status sLastStatus;
|
||||
|
||||
const char *MDAL_Version()
|
||||
{
|
||||
return "0.1.4";
|
||||
return "0.1.5";
|
||||
}
|
||||
|
||||
MDAL_Status MDAL_LastStatus()
|
||||
|
54
external/mdal/mdal_utils.cpp
vendored
54
external/mdal/mdal_utils.cpp
vendored
@ -44,27 +44,51 @@ bool MDAL::endsWith( const std::string &str, const std::string &substr, Contains
|
||||
return endsWith( toLower( str ), toLower( substr ), ContainsBehaviour::CaseSensitive );
|
||||
}
|
||||
|
||||
std::vector<std::string> MDAL::split( const std::string &str, const std::string &delimiter, SplitBehaviour behaviour )
|
||||
std::vector<std::string> MDAL::split( const std::string &str,
|
||||
const char delimiter
|
||||
)
|
||||
{
|
||||
std::string remaining( str );
|
||||
std::vector<std::string> list;
|
||||
size_t pos = 0;
|
||||
std::string::const_iterator start = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
std::string::const_iterator next;
|
||||
std::string token;
|
||||
while ( ( pos = remaining.find( delimiter ) ) != std::string::npos )
|
||||
do
|
||||
{
|
||||
token = remaining.substr( 0, pos );
|
||||
|
||||
if ( behaviour == SplitBehaviour::SkipEmptyParts )
|
||||
{
|
||||
if ( !token.empty() )
|
||||
list.push_back( token );
|
||||
}
|
||||
else
|
||||
next = std::find( start, end, delimiter );
|
||||
token = std::string( start, next );
|
||||
if ( !token.empty() )
|
||||
list.push_back( token );
|
||||
|
||||
remaining.erase( 0, pos + delimiter.length() );
|
||||
if ( next == end )
|
||||
break;
|
||||
else
|
||||
start = next + 1;
|
||||
}
|
||||
list.push_back( remaining );
|
||||
while ( true );
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> MDAL::split( const std::string &str,
|
||||
const std::string &delimiter )
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type next;
|
||||
std::string token;
|
||||
do
|
||||
{
|
||||
next = str.find( delimiter, start );
|
||||
if ( next == std::string::npos )
|
||||
token = str.substr( start ); // rest of the string
|
||||
else
|
||||
token = str.substr( start, next - start ); // part of the string
|
||||
if ( !token.empty() )
|
||||
list.push_back( token );
|
||||
start = next + delimiter.size();
|
||||
}
|
||||
while ( next != std::string::npos );
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -308,7 +332,7 @@ double MDAL::parseTimeUnits( const std::string &units )
|
||||
// "seconds since 2001-05-05 00:00:00"
|
||||
// "hours since 1900-01-01 00:00:0.0"
|
||||
// "days since 1961-01-01 00:00:00"
|
||||
const std::vector<std::string> units_list = MDAL::split( units, " since ", SkipEmptyParts );
|
||||
const std::vector<std::string> units_list = MDAL::split( units, " since " );
|
||||
if ( units_list.size() == 2 )
|
||||
{
|
||||
// Give me hours
|
||||
|
21
external/mdal/mdal_utils.hpp
vendored
21
external/mdal/mdal_utils.hpp
vendored
@ -6,6 +6,10 @@
|
||||
#ifndef MDAL_UTILS_HPP
|
||||
#define MDAL_UTILS_HPP
|
||||
|
||||
// Macro for exporting symbols
|
||||
// for unit tests (on windows)
|
||||
#define MDAL_TEST_EXPORT MDAL_EXPORT
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stddef.h>
|
||||
@ -59,12 +63,15 @@ namespace MDAL
|
||||
bool toBool( const std::string &str );
|
||||
bool isNumber( const std::string &str );
|
||||
|
||||
enum SplitBehaviour
|
||||
{
|
||||
SkipEmptyParts,
|
||||
KeepEmptyParts
|
||||
};
|
||||
std::vector<std::string> split( const std::string &str, const std::string &delimiter, SplitBehaviour behaviour );
|
||||
/**
|
||||
* Splits by deliminer and skips empty parts.
|
||||
* Faster than version with std::string
|
||||
*/
|
||||
MDAL_TEST_EXPORT std::vector<std::string> split( const std::string &str, const char delimiter );
|
||||
|
||||
//! Splits by deliminer and skips empty parts
|
||||
MDAL_TEST_EXPORT std::vector<std::string> split( const std::string &str, const std::string &delimiter );
|
||||
|
||||
std::string join( const std::vector<std::string> parts, const std::string &delimiter );
|
||||
|
||||
//! Right trim
|
||||
@ -87,7 +94,7 @@ namespace MDAL
|
||||
|
||||
// time
|
||||
//! Returns a delimiter to get time in hours
|
||||
double parseTimeUnits( const std::string &units );
|
||||
MDAL_TEST_EXPORT double parseTimeUnits( const std::string &units );
|
||||
|
||||
// statistics
|
||||
void combineStatistics( Statistics &main, const Statistics &other );
|
||||
|
Loading…
x
Reference in New Issue
Block a user