void QgsMapToolAddCircle::deactivate() { if ( !mParentTool || mCircle.isEmpty() ) { return; } mParentTool->clearCurve(); // keep z value from the first snapped point std::unique_ptr<QgsCircularString> lineString( mCircle.toCircularString() ); for ( const QgsPoint point : qgis::as_const( mPoints ) ) { if ( QgsWkbTypes::hasZ( point.wkbType() ) && point.z() != defaultZValue() ) { lineString->dropZValue(); lineString->addZValue( point.z() ); break; } } mParentTool->addCurve( lineString.release() ); clean(); QgsMapToolCapture::deactivate(); }
bool CIniFile::open(const char * fileName) { std::ifstream fin(fileName); if(!fin.is_open()) { return false; } m_key2Value.clear(); fin.seekg( 0, std::ios::beg ); char buffer[255]; while( fin.getline(buffer,255) ) { std::string lineString(buffer); std::string::size_type loc = lineString.find(EQUAL); if(std::string::npos != loc) { std::string keyWithSpace=lineString.substr(0,loc); std::string key= CStrUtil::removeSpace(keyWithSpace); std::string value= lineString.substr(loc+1); value= CStrUtil::removeSpace(value); if(!key.empty() && !value.empty()) m_key2Value[key]= CStrUtil::removeSpace(value); } memset(buffer, 0, 255); } fin.close(); return true; }
GeoDataLineString GeoDataLineString::optimized () const { if( isClosed() ) { GeoDataLinearRing linearRing(*this); p()->optimize(linearRing); return linearRing; } else { GeoDataLineString lineString(*this); p()->optimize(lineString); return lineString; } }
std::string operator()(const Ring * v) const { // Ring is currently getting special treatment // because we want it to be represented as // a LineString in WKT terms. // // Boost will product a Polygon if sent through // as a Ring type. // gf::LineString lineString(*v); std::stringstream stringStream; stringStream << boost::geometry::wkt<gf::LineString>(lineString); return stringStream.str(); }
std::string Timing::getAllMeasureTable() { unsigned int maxStringSize = 5; std::string table; std::map<std::string, long int>::iterator iter = this->timeMap.begin(); for( ; iter != this->timeMap.end() ; ++iter ) { if( (*iter).first.size() > maxStringSize ) { maxStringSize = (*iter).first.size(); } } std::string lineString( maxStringSize+25 , '-'); table += lineString; table += "\n| "; table += ( (maxStringSize>5) ? std::string(maxStringSize-5, ' ') + std::string("LABEL") : std::string("LABEL") ); table += " | SEC | mSEC | uSEC |\n"; table += lineString; iter = this->timeMap.begin(); for( ; iter != this->timeMap.end() ; ++iter ) { std::string id = (*iter).first; elapsedTime et = this->getMeasure(id); std::string et_usec = this->tostr(et.microSecond); std::string et_msec = this->tostr(et.miliSecond); std::string et_sec = this->tostr(et.second); table += "\n| "; table += ( (id.size() < maxStringSize) ? std::string(maxStringSize-id.size(), ' ') + id : id ); table += " | "; table += ( (et_sec.size() < 4) ? std::string(4-et_sec.size(), ' ') + et_sec : et_sec ); table += " | "; table += ( (et_msec.size() < 4) ? std::string(4-et_msec.size(), ' ') + et_msec : et_msec ); table += " | "; table += ( (et_usec.size() < 4) ? std::string(4-et_usec.size(), ' ') + et_usec : et_usec ); table += " |\n"; table += lineString; } table += "\n"; return table; }
QString QgsMultiCurve::asJson( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [" ); for ( const QgsAbstractGeometry *geom : mGeometries ) { if ( qgsgeometry_cast<const QgsCurve *>( geom ) ) { std::unique_ptr< QgsLineString > lineString( static_cast<const QgsCurve *>( geom )->curveToLine() ); QgsPointSequence pts; lineString->points( pts ); json += QgsGeometryUtils::pointsToJSON( pts, precision ) + QLatin1String( ", " ); } } if ( json.endsWith( QLatin1String( ", " ) ) ) { json.chop( 2 ); // Remove last ", " } json += QLatin1String( "] }" ); return json; }
QDomElement QgsMultiCurve::asGml2( QDomDocument &doc, int precision, const QString &ns, const AxisOrder axisOrder ) const { // GML2 does not support curves QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral( "MultiLineString" ) ); if ( isEmpty() ) return elemMultiLineString; for ( const QgsAbstractGeometry *geom : mGeometries ) { if ( qgsgeometry_cast<const QgsCurve *>( geom ) ) { std::unique_ptr< QgsLineString > lineString( static_cast<const QgsCurve *>( geom )->curveToLine() ); QDomElement elemLineStringMember = doc.createElementNS( ns, QStringLiteral( "lineStringMember" ) ); elemLineStringMember.appendChild( lineString->asGml2( doc, precision, ns, axisOrder ) ); elemMultiLineString.appendChild( elemLineStringMember ); } } return elemMultiLineString; }
void ZWWebengineView::initJSList() { m_jsList.clear(); QString key = "//========//"; QFile file(":/res/all.js"); if(file.open(QIODevice::ReadOnly)) { QString jsString; while(!file.atEnd()) { QString lineString(file.readLine()); if(lineString.startsWith(key)) { // jsString.append(lineString); if(!jsString.isEmpty()) { m_jsList.append(jsString); } jsString = ""; } else if(lineString.startsWith("//") || lineString == "\n") { continue; } else { jsString.append(lineString); jsString.append("\n"); } // ZW_LOG_INFO(jsString); } file.close(); } else { ZW_LOG_CRITICAL("open file is error"); } ZW_LOG_INFO(QString("jslistcount=%1").arg(m_jsList.count())); }
void KMLGPSDataParser::CreateTrackLine(QDomElement& parent, QDomDocument& root, int altitudeMode) { kmlDocument = &root; // add the linetrack QDomElement kmlPlacemark = addKmlElement(parent, QLatin1String("Placemark")); addKmlTextElement(kmlPlacemark, QLatin1String("name"), i18n("Track")); QDomElement kmlLineString = addKmlElement(kmlPlacemark, QLatin1String("LineString")); addKmlTextElement(kmlLineString, QLatin1String("coordinates"), lineString()); addKmlTextElement(kmlPlacemark, QLatin1String("styleUrl"), QLatin1String("#linetrack")); if (altitudeMode == 2 ) { addKmlTextElement(kmlLineString, QLatin1String("altitudeMode"), QLatin1String("absolute")); } else if (altitudeMode == 1 ) { addKmlTextElement(kmlLineString, QLatin1String("altitudeMode"), QLatin1String("relativeToGround")); } else { addKmlTextElement(kmlLineString, QLatin1String("altitudeMode"), QLatin1String("clampToGround")); } }
int main( int argc, char* argv[] ) { int resultCode = EXIT_SUCCESS; std::string dataset; std::string input; std::string output; bool smallClusters; unsigned int activeClusters; boost::program_options::options_description description( "Allowed options" ); description.add_options() ( "help,h", "display this help" ) ( "file,f", boost::program_options::value< std::string >( &dataset ), "dataset file (SVM-Light format)" ) ( "input,i", boost::program_options::value< std::string >( &input ), "input model file" ) ( "output,o", boost::program_options::value< std::string >( &output ), "output text file" ) ( "small_clusters,s", boost::program_options::value< bool >( &smallClusters )->default_value( false ), "use size-16 instead of size-256 clusters?" ) ( "active_clusters,a", boost::program_options::value< unsigned int >( &activeClusters )->default_value( 64 ), "number of \"active\" clusters" ) ; try { boost::program_options::variables_map variables; boost::program_options::store( boost::program_options::command_line_parser( argc, argv ).options( description ).run(), variables ); boost::program_options::notify( variables ); if ( variables.count( "help" ) ) { std::cout << "Classifies a dataset (in SVM-Light format). For binary classifiers, the result" << std::endl << "is saved to a text file containing one floating-point number per line: the" << std::endl << "value of the classification function applied the corresponding testing vector" << std::endl << "(the signs of these numbers are the classifications). For multiclass" << std::endl << "classifiers, each line of the output file contains a comma-separated list of" << std::endl << "values of the classification functions of the classes, applied to the" << std::endl << "corresponding testing vector (the index of the largest of these is the" << std::endl << "classification)." << std::endl << std::endl << "This implementation handles sparsity using a greedy clustering approach. The" << std::endl << "small_clusters parameter indicates the size of the clusters: 16 (small) or 256" << std::endl << "(not small). Generally, size-256 clusters will give significantly better" << std::endl << "performance. The active_clusters parameter is the number of clusters which will" << std::endl << "be active at every point in the greedy clustering algorithm. We have found that" << std::endl << "64 works well, but increasing this number will improve the quality of the" << std::endl << "clustering (at the cost of more time being required to find it)." << std::endl << std::endl << description << std::endl; } else { if ( ! variables.count( "file" ) ) throw std::runtime_error( "You must provide a dataset file" ); if ( ! variables.count( "input" ) ) throw std::runtime_error( "You must provide an input file" ); if ( ! variables.count( "output" ) ) throw std::runtime_error( "You must provide an output file" ); // load the dataset file unsigned int rows = 0; unsigned int columns = 0; std::vector< float > values; std::vector< size_t > indices; std::vector< size_t > offsets; { unsigned int const bufferSize = ( 1u << 24 ); boost::shared_array< char > buffer( new char[ bufferSize ] ); const boost::regex spaceRegex( "[[:space:]]+" ); const boost::regex elementRegex( "^[[:space:]]*([[:digit:]]+):(-?[[:digit:]]+(\\.[[:digit:]]+)?([eE]-?[[:digit:]]+)?)[[:space:]]*$" ); offsets.push_back( 0 ); std::ifstream file( dataset.c_str() ); if ( file.fail() ) throw std::runtime_error( "Unable to open dataset file" ); while ( ! file.eof() ) { file.getline( buffer.get(), bufferSize ); if ( file.fail() ) break; std::string lineString( buffer.get() ); boost::sregex_token_iterator ii( lineString.begin(), lineString.end(), spaceRegex, -1 ); boost::sregex_token_iterator iiEnd; if ( ii != iiEnd ) { // ignore blank lines std::string const signString = ii->str(); if ( ii == iiEnd ) throw std::runtime_error( "Failed to parse first element of dataset line" ); // we don't care about the value of the label, since we're classifying int lastIndex = -1; for ( ++ii; ii != iiEnd; ++ii ) { std::string const elementString = ii->str(); boost::smatch elementMatch; if ( ! boost::regex_match( elementString, elementMatch, elementRegex, boost::match_extra ) ) throw std::runtime_error( "Failed to parse element of dataset line" ); std::string const indexString = elementMatch[ 1 ].str(); int index = atoi( indexString.c_str() ); std::string const valueString = elementMatch[ 2 ].str(); float const value = static_cast< float >( atof( valueString.c_str() ) ); if ( index < 0 ) throw std::runtime_error( "Failed to parse element of dataset line: negative index encountered" ); if ( index <= lastIndex ) throw std::runtime_error( "Failed to parse element of dataset line: features must be listed in order of increasing index" ); lastIndex = index; if ( value != 0 ) { values.push_back( value ); indices.push_back( index ); if ( index + 1 > static_cast< int >( columns ) ) columns = index + 1; } } BOOST_ASSERT( values.size() == indices.size() ); offsets.push_back( values.size() ); } } file.close(); rows = offsets.size() - 1; } AutoContext context; if ( GTSVM_Load( context, input.c_str(), false, 1 ) ) { throw std::runtime_error( GTSVM_Error() ); } if ( GTSVM_Shrink( context, smallClusters, activeClusters ) ) { throw std::runtime_error( GTSVM_Error() ); } unsigned int classes; if ( GTSVM_GetClasses( context, &classes ) ) { throw std::runtime_error( GTSVM_Error() ); } boost::shared_array< double > result( new double[ rows * classes ] ); if ( GTSVM_ClassifySparse( context, result.get(), GTSVM_TYPE_DOUBLE, &values[ 0 ], &indices[ 0 ], &offsets[ 0 ], GTSVM_TYPE_FLOAT, rows, columns, false ) ) { throw std::runtime_error( GTSVM_Error() ); } { std::ofstream file( output.c_str() ); if ( file.fail() ) throw std::runtime_error( "Unable to open output file" ); for ( unsigned int ii = 0; ii < rows; ++ii ) { file << result[ ii * classes + 0 ]; for ( unsigned int jj = 1; jj < classes; ++jj ) file << ", " << result[ ii * classes + jj ]; file << std::endl; } file.close(); } } } catch( std::exception& error ) { std::cerr << "Error: " << error.what() << std::endl << std::endl << description << std::endl; resultCode = EXIT_FAILURE; } return resultCode; }