void SpatialReference::setFromUserInput(std::string const& v) { if (v.empty()) { m_wkt.clear(); return; } OGRSpatialReference srs(NULL); CPLErrorReset(); const char* input = v.c_str(); OGRErr err = srs.SetFromUserInput(const_cast<char *>(input)); if (err != OGRERR_NONE) { std::ostringstream oss; std::string msg = CPLGetLastErrorMsg(); if (msg.empty()) msg = "(unknown reason)"; oss << "Could not import coordinate system '" << input << "': " << msg << "."; throw pdal_error(oss.str()); } char *poWKT = 0; srs.exportToWkt(&poWKT); std::string tmp(poWKT); CPLFree(poWKT); setWKT(tmp); }
void GenMarkSweep::mark_sweep_phase3() { GenCollectedHeap* gch = GenCollectedHeap::heap(); // Adjust the pointers to reflect the new locations GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer()); // Need new claim bits for the pointer adjustment tracing. ClassLoaderDataGraph::clear_claimed_marks(); // Because the closure below is created statically, we cannot // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. adjust_pointer_closure.set_orig_generation(gch->old_gen()); { StrongRootsScope srs(1); gch->gen_process_roots(&srs, GenCollectedHeap::OldGen, false, // Younger gens are not roots. GenCollectedHeap::SO_AllCodeCache, GenCollectedHeap::StrongAndWeakRoots, &adjust_pointer_closure, &adjust_pointer_closure, &adjust_cld_closure); } gch->gen_process_weak_roots(&adjust_pointer_closure); adjust_marks(); GenAdjustPointersClosure blk; gch->generation_iterate(&blk, true); }
int main(int argc, char** argv) { Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams; pParams->setMaxQueued(100); pParams->setMaxThreads(16); // do tcp bind and listen Poco::Net::ServerSocket srs(8080); // register client handler factory Poco::Net::HTTPServer srv (new MyHTTPRequestHandlerFactory, srs, pParams); // Start TCP server srv.start(); // wait forever while (1) { sleep(1); } // Stop the TCP Server srv.stop(); return 0; }
void QgsProjectProperties::setMapUnitsToCurrentProjection() { long myCRSID = projectionSelector->selectedCrsId(); if ( myCRSID ) { QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId ); //set radio button to crs map unit type QGis::UnitType units = srs.mapUnits(); switch ( units ) { case QGis::Meters: radMeters->setChecked( true ); break; case QGis::Feet: radFeet->setChecked( true ); break; case QGis::Degrees: radDecimalDegrees->setChecked( true ); break; case QGis::DegreesMinutesSeconds: radDMS->setChecked( true ); break; default: break; } } }
void QgsVectorLayerSaveAsDialog::setup() { setupUi( this ); QSettings settings; restoreGeometry( settings.value( "/Windows/VectorLayerSaveAs/geometry" ).toByteArray() ); QMap<QString, QString> map = QgsVectorFileWriter::ogrDriverList(); mFormatComboBox->blockSignals( true ); for ( QMap< QString, QString>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it ) { mFormatComboBox->addItem( it.key(), it.value() ); } QString format = settings.value( "/UI/lastVectorFormat", "ESRI Shapefile" ).toString(); mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) ); mFormatComboBox->blockSignals( false ); //add geometry types to combobox mGeometryTypeComboBox->addItem( tr( "Automatic" ), -1 ); mGeometryTypeComboBox->addItem( QgsWKBTypes::displayString( QgsWKBTypes::Point ), QgsWKBTypes::Point ); mGeometryTypeComboBox->addItem( QgsWKBTypes::displayString( QgsWKBTypes::LineString ), QgsWKBTypes::LineString ); mGeometryTypeComboBox->addItem( QgsWKBTypes::displayString( QgsWKBTypes::Polygon ), QgsWKBTypes::Polygon ); mGeometryTypeComboBox->addItem( QgsWKBTypes::displayString( QgsWKBTypes::GeometryCollection ), QgsWKBTypes::GeometryCollection ); mGeometryTypeComboBox->addItem( tr( "No geometry" ), QgsWKBTypes::NoGeometry ); mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) ); mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() ); QString enc = settings.value( "/UI/encoding", "System" ).toString(); int idx = mEncodingComboBox->findText( enc ); if ( idx < 0 ) { mEncodingComboBox->insertItem( 0, enc ); idx = 0; } QgsCoordinateReferenceSystem srs( mCRS, QgsCoordinateReferenceSystem::InternalCrsId ); mCrsSelector->setCrs( srs ); mCrsSelector->setLayerCrs( srs ); mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the vector file. " "The data points will be transformed from the layer coordinate reference system." ) ); mEncodingComboBox->setCurrentIndex( idx ); on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() ); //symbology export combo box mSymbologyExportComboBox->addItem( tr( "No symbology" ), QgsVectorFileWriter::NoSymbology ); mSymbologyExportComboBox->addItem( tr( "Feature symbology" ), QgsVectorFileWriter::FeatureSymbology ); mSymbologyExportComboBox->addItem( tr( "Symbol layer symbology" ), QgsVectorFileWriter::SymbolLayerSymbology ); on_mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() ); // extent group box mExtentGroupBox->setOutputCrs( srs ); mExtentGroupBox->setOriginalExtent( mLayerExtent, srs ); mExtentGroupBox->setOutputExtentFromOriginal(); mExtentGroupBox->setCheckable( true ); mExtentGroupBox->setChecked( false ); mExtentGroupBox->setCollapsed( true ); }
void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { // Recursively traverse all live objects and mark them GCTraceTime(Trace, gc) tm("Phase 1: Mark live objects", _gc_timer); GenCollectedHeap* gch = GenCollectedHeap::heap(); // Because follow_root_closure is created statically, cannot // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. follow_root_closure.set_orig_generation(gch->old_gen()); // Need new claim bits before marking starts. ClassLoaderDataGraph::clear_claimed_marks(); { StrongRootsScope srs(1); gch->gen_process_roots(&srs, GenCollectedHeap::OldGen, false, // Younger gens are not roots. GenCollectedHeap::SO_None, ClassUnloading, &follow_root_closure, &follow_root_closure, &follow_cld_closure); } // Process reference objects found during marking { ref_processor()->setup_policy(clear_all_softrefs); const ReferenceProcessorStats& stats = ref_processor()->process_discovered_references( &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer); gc_tracer()->report_gc_reference_stats(stats); } // This is the point where the entire marking should have completed. assert(_marking_stack.is_empty(), "Marking should have completed"); // Unload classes and purge the SystemDictionary. bool purged_class = SystemDictionary::do_unloading(&is_alive); // Unload nmethods. CodeCache::do_unloading(&is_alive, purged_class); // Prune dead klasses from subklass/sibling/implementor lists. Klass::clean_weak_klass_links(&is_alive); // Delete entries for dead interned strings. StringTable::unlink(&is_alive); // Clean up unreferenced symbols in symbol table. SymbolTable::unlink(); gc_tracer()->report_object_count_after_gc(&is_alive); }
/* * Class: mapnik_MapDefinition * Method: alloc * Signature: (IILjava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_mapnik_MapDefinition_alloc__IILjava_lang_String_2 (JNIEnv *env, jclass c, jint width, jint height, jstring srsj) { PREAMBLE; refjavastring srs(env, srsj); return FROM_POINTER(new mapnik::Map(width, height, srs.stringz)); TRAILER(0); }
void QgsGrassNewMapset::setCurrentRegion() { QgsDebugMsg( "entered." ); QgsRectangle ext = mIface->mapCanvas()->extent(); int srsid = QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectCRSID", 0 ); QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId ); QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) ); QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) ); std::vector<QgsPoint> points; // TODO: this is not perfect points.push_back( QgsPoint( ext.xMinimum(), ext.yMinimum() ) ); points.push_back( QgsPoint( ext.xMaximum(), ext.yMaximum() ) ); // TODO add a method, this code is copy-paste from setSelectedRegion if ( srs.isValid() && mSrs.isValid() && srs.srsid() != mSrs.srsid() ) { QgsCoordinateTransform trans( srs, mSrs ); bool ok = true; for ( int i = 0; i < 2; i++ ) { try { points[i] = trans.transform( points[i] ); } catch ( QgsCsException &cse ) { Q_UNUSED( cse ); QgsDebugMsg( "Cannot transform point" ); ok = false; break; } } if ( !ok ) { QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot reproject region" ) ); return; } } mNorthLineEdit->setText( QString::number( points[1].y() ) ); mSouthLineEdit->setText( QString::number( points[0].y() ) ); mEastLineEdit->setText( QString::number( points[1].x() ) ); mWestLineEdit->setText( QString::number( points[0].x() ) ); mRegionModified = true; checkRegion(); drawRegion(); QgsDebugMsg( "setCurrentRegion - End" ); }
/* * Class: mapnik_MapDefinition * Method: setSrs * Signature: ()Ljava/lang/String; */ JNIEXPORT void JNICALL Java_mapnik_MapDefinition_setSrs (JNIEnv *env, jobject mapobject, jstring srsj) { PREAMBLE; mapnik::Map* map=LOAD_MAP_POINTER(mapobject); refjavastring srs(env, srsj); map->set_srs(srs.stringz); TRAILER_VOID; }
/* * Class: mapnik_Layer * Method: alloc * Signature: (Ljava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_mapnik_Layer_alloc (JNIEnv *env, jclass c, jstring namej, jstring srsj) { ASSERT_INITIALIZED; refjavastring name(env, namej); refjavastring srs(env, srsj); mapnik::layer* layer=new mapnik::layer(name.stringz, srs.stringz); return FROM_POINTER(layer); }
/* * Class: mapnik_Layer * Method: alloc * Signature: (Ljava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_mapnik_Layer_alloc (JNIEnv *env, jclass c, jstring namej, jstring srsj) { PREAMBLE; refjavastring name(env, namej); refjavastring srs(env, srsj); mapnik::layer* layer=new mapnik::layer(name.stringz, srs.stringz); return FROM_POINTER(layer); TRAILER(0); }
void MapReprojector::reprojectToWgs84(shared_ptr<OsmMap> map) { if (isGeographic(map) == false) { MapReprojector proj; shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); //srs->importFromEPSG(4326); srs->SetWellKnownGeogCS("WGS84"); proj.reproject(map, srs); } }
shared_ptr<OGRSpatialReference> MapReprojector::createOrthographic(const OGREnvelope& env) { shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); double x = (env.MinX + env.MaxX) / 2.0; double y = (env.MinY + env.MaxY) / 2.0; if (srs->SetOrthographic(y, x, 0, 0) != OGRERR_NONE) { throw HootException("Error creating orthographic projection."); } return srs; }
void MapReprojector::reprojectToOrthographic(shared_ptr<OsmMap> map, const OGREnvelope& env) { MapReprojector proj; shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); double x = (env.MinX + env.MaxX) / 2.0; double y = (env.MinY + env.MaxY) / 2.0; if (srs->SetOrthographic(y, x, 0, 0) != OGRERR_NONE) { throw HootException("Error creating orthographic projection."); } proj.reproject(map, srs); }
shared_ptr<OGRSpatialReference> MapReprojector::createSinusoidalProjection(const OGREnvelope& env) { double centerLon = (env.MaxX + env.MinX) / 2.0; shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); if (srs->SetSinusoidal(centerLon, 0.0, 0.0) != OGRERR_NONE) { throw HootException("Error creating sinusoidal projection."); } return srs; }
shared_ptr<OGRSpatialReference> MapReprojector::createWgs84Projection() { shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); // EPSG 4326 = WGS84 // if (srs->SetWellKnownGeogCS("WGS84") != OGRERR_NONE) if (srs->importFromEPSG(4326) != OGRERR_NONE) { throw HootException("Error creating EPSG:4326 projection."); } return srs; }
void QgsVectorLayerSaveAsDialog::setup() { setupUi( this ); QSettings settings; restoreGeometry( settings.value( "/Windows/VectorLayerSaveAs/geometry" ).toByteArray() ); QMap<QString, QString> map = QgsVectorFileWriter::ogrDriverList(); mFormatComboBox->blockSignals( true ); for ( QMap< QString, QString>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it ) { mFormatComboBox->addItem( it.key(), it.value() ); } QString format = settings.value( "/UI/lastVectorFormat", "ESRI Shapefile" ).toString(); mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) ); mFormatComboBox->blockSignals( false ); mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() ); QString enc = settings.value( "/UI/encoding", "System" ).toString(); int idx = mEncodingComboBox->findText( enc ); if ( idx < 0 ) { mEncodingComboBox->insertItem( 0, enc ); idx = 0; } mCRSSelection->clear(); mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) ); QgsCoordinateReferenceSystem srs( mCRS, QgsCoordinateReferenceSystem::InternalCrsId ); leCRS->setText( srs.description() ); mEncodingComboBox->setCurrentIndex( idx ); on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() ); //symbology export combo box mSymbologyExportComboBox->addItem( tr( "No symbology" ), QgsVectorFileWriter::NoSymbology ); mSymbologyExportComboBox->addItem( tr( "Feature symbology" ), QgsVectorFileWriter::FeatureSymbology ); mSymbologyExportComboBox->addItem( tr( "Symbol layer symbology" ), QgsVectorFileWriter::SymbolLayerSymbology ); on_mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() ); // extent group box mExtentGroupBox->setOutputCrs( srs ); mExtentGroupBox->setOriginalExtent( mLayerExtent, srs ); mExtentGroupBox->setOutputExtentFromOriginal(); mExtentGroupBox->setCheckable( true ); mExtentGroupBox->setChecked( false ); mExtentGroupBox->setCollapsed( true ); }
void SpatialReference::setProj4(std::string const& v) { char* poWKT = 0; const char* poProj4 = v.c_str(); OGRSpatialReference srs(NULL); if (OGRERR_NONE != srs.importFromProj4(const_cast<char *>(poProj4))) { throw std::invalid_argument("could not import proj4 into OSRSpatialReference SetProj4"); } srs.exportToWkt(&poWKT); m_wkt = poWKT; CPLFree(poWKT); }
void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked() { QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(); if( mCRS >= 0 ) mySelector->setSelectedCrsId( mCRS ); mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. " "The data points will be transformed from the layer coordinate reference system." ) ); if( mySelector->exec() ) { QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId ); mCRS = srs.srsid(); leCRS->setText( srs.description() ); } delete mySelector; }
std::string Polygon::json(double precision) const { std::ostringstream prec; prec << precision; char **papszOptions = NULL; papszOptions = CSLSetNameValue(papszOptions, "COORDINATE_PRECISION", prec.str().c_str() ); std::string w(wkt()); gdal::SpatialRef srs(m_srs.getWKT(pdal::SpatialReference::eCompoundOK)); gdal::Geometry g(w, srs); char* json = OGR_G_ExportToJsonEx(g.get(), papszOptions); std::string output(json); OGRFree(json); return output; }
void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked() { QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this ); mySelector->setMessage(); mySelector->setSelectedCrsId( layer->crs().srsid() ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId ); layer->setCrs( srs ); } else { QApplication::restoreOverrideCursor(); } delete mySelector; leSpatialRefSys->setText( layer->crs().authid() + " - " + layer->crs().description() ); leSpatialRefSys->setCursorPosition( 0 ); }
std::string SpatialReference::getHorizontalUnits() const { std::string tmp(""); std::string wkt = getWKT(eHorizontalOnly); const char* poWKT = wkt.c_str(); OGRSpatialReference srs(NULL); if (OGRERR_NONE == srs.importFromWkt(const_cast<char **>(&poWKT))) { char* units(0); double u = srs.GetLinearUnits(&units); tmp = units; CPLFree(units); Utils::trim(tmp); } return tmp; }
std::string SpatialReference::getProj4() const { std::string tmp; std::string wkt = getWKT(eCompoundOK); const char* poWKT = wkt.c_str(); OGRSpatialReference srs(NULL); if (OGRERR_NONE == srs.importFromWkt(const_cast<char **>(&poWKT))) { char* proj4 = 0; srs.exportToProj4(&proj4); tmp = proj4; CPLFree(proj4); Utils::trim(tmp); } return tmp; }
shared_ptr<OGRSpatialReference> MapReprojector::createAeacProjection(const OGREnvelope& env) { shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); double height = env.MaxY - env.MinY; double stdP1 = env.MinY + height * .25; double stdP2 = env.MinY + height * .75; double x = (env.MinX + env.MaxX) / 2.0; double y = (env.MinY + env.MaxY) / 2.0; if (env.MinX == env.MaxX || env.MinY == env.MaxY) { throw HootException("Min and max bounds values cannot be the same."); } if (srs->SetACEA(stdP1, stdP2, y, x, 0, 0) != OGRERR_NONE) { throw HootException("Error creating Albers equal area conic projection."); } return srs; }
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget* parent, Qt::WFlags fl ) : QDialog( parent, fl ) , mCRS( srsid ) { setupUi( this ); QSettings settings; restoreGeometry( settings.value( "/Windows/VectorLayerSaveAs/geometry" ).toByteArray() ); QMap<QString, QString> map = QgsVectorFileWriter::ogrDriverList(); mFormatComboBox->blockSignals( true ); for ( QMap< QString, QString>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it ) { mFormatComboBox->addItem( it.key(), it.value() ); } QString format = settings.value( "/UI/lastVectorFormat", "ESRI Shapefile" ).toString(); mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) ); mFormatComboBox->blockSignals( false ); mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() ); QString enc = settings.value( "/UI/encoding", "System" ).toString(); int idx = mEncodingComboBox->findText( enc ); if ( idx < 0 ) { mEncodingComboBox->insertItem( 0, enc ); idx = 0; } mCRSSelection->clear(); mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) ); QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId ); leCRS->setText( srs.description() ); mEncodingComboBox->setCurrentIndex( idx ); on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() ); }
void GraphComparator::drawCostDistance(shared_ptr<OsmMap> map, vector<Coordinate>& c, QString output) { _updateBounds(); // make a copy of the map so we can manipulate it. map.reset(new OsmMap(map)); for (size_t i = 0; i < c.size(); i++) { cout << c[i].x << " " << c[i].y << endl; c[i] = _findNearestPointOnFeature(map, c[i]); cout << c[i].x << " " << c[i].y << endl; // find the nearest feature long wId = map->getIndex().findNearestWay(c[i]); shared_ptr<Way> w = map->getWay(wId); // split way at c WayLocation wl = LocationOfPoint::locate(map, w, c[i]); vector< shared_ptr<Way> > v = WaySplitter::split(map, w, wl); wl = LocationOfPoint::locate(map, v[0], c[i]); assert(wl.isNode() == true); } // populate graph shared_ptr<DirectedGraph> graph(new DirectedGraph()); graph->deriveEdges(map); LOG_WARN("Running cost"); ShortestPath sp(graph); for (size_t i = 0; i < c.size(); i++) { long wId = map->getIndex().findNearestWay(c[i]); shared_ptr<Way> w = map->getWay(wId); WayLocation wl = LocationOfPoint::locate(map, w, c[i]); // set cost at c to zero. long sourceId = w->getNodeId(wl.getSegmentIndex()); sp.setNodeCost(sourceId, 0.0); } // calculate cost sp.calculateCost(); LOG_WARN("Cost done"); cv::Mat mat = _paintGraph(map, *graph, sp); _saveImage(mat, output, -1.0, false); _saveImage(mat, output.replace(".png", "2.png"), -1.0, true); shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); srs->importFromEPSG(900913); Coordinate c1 = MapProjector::project(Coordinate(_projectedBounds.MinX, _projectedBounds.MinY), map->getProjection(), srs); cout << "coord " << c1.x << ", " << c1.y << endl; Coordinate c2 = MapProjector::project(Coordinate(_projectedBounds.MaxX, _projectedBounds.MaxY), map->getProjection(), srs); cout << "coord2 " << c2.x << ", " << c2.y << endl; printf("POSITION_Y=%f\n", (c1.y + c2.y) / 2.0); //cout << "POSITION_Y=" << (c1.y + c2.y) / 2.0 << endl; printf("POSITION_X=%f\n", (c1.x + c2.x) / 2.0); //cout << "POSITION_X=" << (c1.x + c2.x) / 2.0 << endl; cout << "M12=0.0" << endl; cout << "M11=1.0" << endl; cout << "M10=0.0" << endl; cout << "M02=0.0" << endl; cout << "INITIAL_SCALE=" << (c2.x - c1.x) / (double)_width * 100.0 << endl; cout << "M01=0.0" << endl; cout << "M00=1.0" << endl; // paint graph onto raster //_exportGraphImage(map, *graph, sp, output); }
void QgsGrassNewMapset::pageSelected( int index ) { QgsDebugMsg( QString( "title = %1" ).arg( page( index ) ? page( index )->title() : "(null)" ) ); switch ( index ) { case LOCATION: if ( mPreviousPage == DATABASE ) { setLocationPage(); } break; case CRS: // Projection selector if ( !mProjectionSelector ) { QGridLayout *projectionLayout = new QGridLayout( mProjectionFrame ); mProjectionSelector = new QgsProjectionSelector( mProjectionFrame, "Projection", 0 ); mProjectionSelector->setEnabled( false ); projectionLayout->addWidget( mProjectionSelector, 0 , 0 ); mProjectionSelector->show(); connect( mProjectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( sridSelected( QString ) ) ); // Se current QGIS projection int srsid = QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectCRSID", 0 ); QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId ); QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) ); QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) ); if ( srs.isValid() ) { mProjectionSelector->setSelectedCrsId( srsid ); mProjRadioButton->setChecked( true ); projRadioSwitched(); } } if ( mPreviousPage == LOCATION ) { setProjectionPage(); } break; case REGION: if ( !mRegionsInited ) { loadRegions(); mRegionsInited = true; } if ( mPreviousPage == CRS ) { setRegionPage(); } break; case MAPSET: if ( mPreviousPage == LOCATION || mPreviousPage == REGION ) { setMapsets(); mapsetChanged(); } break; case FINISH: setFinishPage(); break; } mPreviousPage = index; }
// this is static QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget* parent, QString* pEnc ) { QgsNewVectorLayerDialog geomDialog( parent ); if ( geomDialog.exec() == QDialog::Rejected ) { return ""; } QGis::WkbType geometrytype = geomDialog.selectedType(); QString fileformat = geomDialog.selectedFileFormat(); QString enc = geomDialog.selectedFileEncoding(); int crsId = geomDialog.selectedCrsId(); QgsDebugMsg( QString( "New file format will be: %1" ).arg( fileformat ) ); QList< QPair<QString, QString> > attributes; geomDialog.attributes( attributes ); QSettings settings; QString lastUsedDir = settings.value( "/UI/lastVectorFileFilterDir", QDir::homePath() ).toString(); QString filterString = QgsVectorFileWriter::filterForDriver( fileformat ); QString fileName = QFileDialog::getSaveFileName( 0, tr( "Save layer as..." ), lastUsedDir, filterString ); if ( fileName.isNull() ) { return ""; } if ( fileformat == "ESRI Shapefile" && !fileName.endsWith( ".shp", Qt::CaseInsensitive ) ) fileName += ".shp"; settings.setValue( "/UI/lastVectorFileFilterDir", QFileInfo( fileName ).absolutePath() ); settings.setValue( "/UI/encoding", enc ); //try to create the new layer with OGRProvider instead of QgsVectorFileWriter QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); QString ogrlib = pReg->library( "ogr" ); // load the data provider QLibrary* myLib = new QLibrary( ogrlib ); bool loaded = myLib->load(); if ( loaded ) { QgsDebugMsg( "ogr provider loaded" ); typedef bool ( *createEmptyDataSourceProc )( const QString&, const QString&, const QString&, QGis::WkbType, const QList< QPair<QString, QString> >&, const QgsCoordinateReferenceSystem * ); createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc ) cast_to_fptr( myLib->resolve( "createEmptyDataSource" ) ); if ( createEmptyDataSource ) { if ( geometrytype != QGis::WKBUnknown ) { QgsCoordinateReferenceSystem srs( crsId, QgsCoordinateReferenceSystem::InternalCrsId ); if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, &srs ) ) { return QString::null; } } else { QgsDebugMsg( "geometry type not recognised" ); return QString::null; } } else { QgsDebugMsg( "Resolving newEmptyDataSource(...) failed" ); return QString::null; } } if ( pEnc ) *pEnc = enc; return fileName; }
QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *parent ) : QWidget( parent ) { setupUi( this ); leSearch->setShowSearchIcon( true ); connect( lstCoordinateSystems, &QTreeWidget::itemDoubleClicked, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystems_itemDoubleClicked ); connect( lstRecent, &QTreeWidget::itemDoubleClicked, this, &QgsProjectionSelectionTreeWidget::lstRecent_itemDoubleClicked ); connect( lstCoordinateSystems, &QTreeWidget::currentItemChanged, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystems_currentItemChanged ); connect( lstRecent, &QTreeWidget::currentItemChanged, this, &QgsProjectionSelectionTreeWidget::lstRecent_currentItemChanged ); connect( cbxHideDeprecated, &QCheckBox::stateChanged, this, &QgsProjectionSelectionTreeWidget::updateFilter ); connect( leSearch, &QgsFilterLineEdit::textChanged, this, &QgsProjectionSelectionTreeWidget::updateFilter ); mPreviewBand = new QgsRubberBand( mAreaCanvas, QgsWkbTypes::PolygonGeometry ); mPreviewBand->setWidth( 4 ); mPreviewBand2 = new QgsRubberBand( mAreaCanvas, QgsWkbTypes::PolygonGeometry ); mPreviewBand2->setWidth( 4 ); QColor rectColor = QColor( 185, 84, 210, 60 ); mPreviewBand2->setColor( rectColor ); mVertexMarker = new QgsVertexMarker( mAreaCanvas ); mVertexMarker->setIconType( QgsVertexMarker::ICON_CROSS ); mVertexMarker->setColor( QColor( 185, 84, 210 ) ); mVertexMarker->setPenWidth( 3 ); QgsCoordinateReferenceSystem srs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); mAreaCanvas->setDestinationCrs( srs ); QString layerPath = QgsApplication::pkgDataPath() + QStringLiteral( "/resources/data/world_map.shp" ); mLayers << new QgsVectorLayer( layerPath ); mAreaCanvas->setLayers( mLayers ); mAreaCanvas->setMapTool( new QgsMapToolPan( mAreaCanvas ) ); mAreaCanvas->setPreviewJobsEnabled( true ); mAreaCanvas->setVisible( mShowMap ); if ( QDialog *dlg = qobject_cast<QDialog *>( parent ) ) { // mark selected projection for push to front if parent dialog is accepted connect( dlg, &QDialog::accepted, this, &QgsProjectionSelectionTreeWidget::pushProjectionToFront ); } // Get the full path name to the sqlite3 spatial reference database. mSrsDatabaseFileName = QgsApplication::srsDatabaseFilePath(); lstCoordinateSystems->header()->setSectionResizeMode( AuthidColumn, QHeaderView::Stretch ); lstCoordinateSystems->header()->resizeSection( QgisCrsIdColumn, 0 ); lstCoordinateSystems->header()->setSectionResizeMode( QgisCrsIdColumn, QHeaderView::Fixed ); // Hide (internal) ID column lstCoordinateSystems->setColumnHidden( QgisCrsIdColumn, true ); lstRecent->header()->setSectionResizeMode( AuthidColumn, QHeaderView::Stretch ); lstRecent->header()->resizeSection( QgisCrsIdColumn, 0 ); lstRecent->header()->setSectionResizeMode( QgisCrsIdColumn, QHeaderView::Fixed ); // Hide (internal) ID column lstRecent->setColumnHidden( QgisCrsIdColumn, true ); mRecentProjections = QgsCoordinateReferenceSystem::recentProjections(); mCheckBoxNoProjection->setHidden( true ); connect( mCheckBoxNoProjection, &QCheckBox::toggled, this, &QgsProjectionSelectionTreeWidget::crsSelected ); connect( mCheckBoxNoProjection, &QCheckBox::toggled, mFrameProjections, &QFrame::setDisabled ); }
int main( int, char*[] ) { try { mapnik::projection srs("foo"); // to avoid unused variable warning srs.params(); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } mapnik::Map map(256,256); mapnik::rule r; r.set_filter(mapnik::parse_expression("[foo]='bar'")); mapnik::feature_type_style style; style.add_rule(r); map.insert_style("style",style); std::string csv_plugin("./plugins/input/csv.input"); if (boost::filesystem::exists(csv_plugin)) { try { mapnik::datasource_cache::instance()->register_datasource(csv_plugin); mapnik::parameters p; p["type"]="csv"; p["inline"]="x,y\n0,0"; mapnik::datasource_ptr ds = mapnik::datasource_cache::instance()->create(p); //mapnik::datasource_ptr ds = boost::make_shared<mapnik::memory_datasource>(); //mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>(); //mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, 1)); //mapnik::memory_datasource *mem_ds = dynamic_cast<mapnik::memory_datasource *>(ds.get()); //mem_ds->push(feature); mapnik::layer l("layer"); l.set_datasource(ds); l.add_style("style"); mapnik::Map m = map; m.addLayer(l); m.zoom_all(); mapnik::image_32 im(m.width(),m.height()); mapnik::agg_renderer<mapnik::image_32> ren(m,im); //std::clog << mapnik::save_map_to_string(m) << "\n"; BOOST_TEST(true); // should throw here ren.apply(); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } } std::string shape_plugin("./plugins/input/shape.input"); if (boost::filesystem::exists(shape_plugin)) { try { mapnik::datasource_cache::instance()->register_datasource(shape_plugin); mapnik::parameters p2; p2["type"]="shape"; p2["file"]="foo"; mapnik::datasource_cache::instance()->create(p2); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } } /* // not working, oddly segfaults valgrind try { sqlite3_initialize(); // http://stackoverflow.com/questions/11107703/sqlite3-sigsegvs-with-valgrind sqlite3_config(SQLITE_CONFIG_HEAP, malloc (1024*1024), 1024*1024, 64); mapnik::datasource_cache::instance()->register_datasource("./plugins/input/sqlite.input"); mapnik::parameters p; p["type"]="sqlite"; p["file"]="tests/data/sqlite/world.sqlite"; p["table"]="world_merc"; mapnik::datasource_cache::instance()->create(p); sqlite3_shutdown(); BOOST_TEST(true); } catch (...) { BOOST_TEST(false); } */ if (!::boost::detail::test_errors()) { std::clog << "C++ exceptions: \x1b[1;32m✓ \x1b[0m\n"; #if BOOST_VERSION >= 104600 ::boost::detail::report_errors_remind().called_report_errors_function = true; #endif } else { return ::boost::report_errors(); } }