| 608 | } |
| 609 | |
| 610 | void Project::SaveDataSourceAs(const wxString& new_ds_name, bool is_update) |
| 611 | { |
| 612 | wxLogMessage("Entering Project::SaveDataSourceAs"); |
| 613 | wxLogMessage("New Datasource Name:" + new_ds_name); |
| 614 | |
| 615 | std::vector<GdaShape*> geometries; |
| 616 | try { |
| 617 | // SaveAs only to same datasource |
| 618 | GdaConst::DataSourceType ds_type = datasource->GetType(); |
| 619 | if (ds_type == GdaConst::ds_dbf ) { |
| 620 | // OGR only support ESRI Shapefile, and doesn't support DBF separatly. |
| 621 | // see : http://www.gdal.org/ogr_formats.html |
| 622 | ds_type = GdaConst::ds_shapefile; |
| 623 | } |
| 624 | |
| 625 | wxString ds_format = IDataSource::GetDataTypeNameByGdaDSType(ds_type); |
| 626 | if ( !IDataSource::IsWritable(ds_type) ) { |
| 627 | wxString error_message = wxString::Format(_("GeoDa does not support creating data of %s. Please try to 'Export' to other supported data source format."), ds_format); |
| 628 | throw GdaException(error_message.mb_str()); |
| 629 | } |
| 630 | // call to initial OGR instance |
| 631 | OGRDataAdapter& ogr_adapter = OGRDataAdapter::GetInstance(); |
| 632 | |
| 633 | // Get spatial reference from this project |
| 634 | OGRSpatialReference* spatial_ref = GetSpatialReference(); |
| 635 | |
| 636 | // Get Gda geometries and convert to OGR geometries from this project |
| 637 | Shapefile::ShapeType shape_type = GetGdaGeometries(geometries); |
| 638 | |
| 639 | // Get default selected rows: all records should be saved or saveas |
| 640 | std::vector<int> selected_rows; |
| 641 | for (size_t i=0; i<table_int->GetNumberRows(); i++) { |
| 642 | selected_rows.push_back(i); |
| 643 | } |
| 644 | |
| 645 | // Create in-memory OGR geometries |
| 646 | std::vector<OGRGeometry*> ogr_geometries; |
| 647 | OGRwkbGeometryType geom_type; |
| 648 | geom_type = ogr_adapter.MakeOGRGeometries(geometries, shape_type, |
| 649 | ogr_geometries, selected_rows); |
| 650 | |
| 651 | // NOTE: for GeoJSON, automatically transform to WGS84 |
| 652 | if (spatial_ref && ds_type == GdaConst::ds_geo_json) { |
| 653 | OGRSpatialReference wgs84_ref; |
| 654 | wgs84_ref.importFromEPSG(4326); |
| 655 | OGRCoordinateTransformation *poCT; |
| 656 | #ifdef __PROJ6__ |
| 657 | spatial_ref->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); |
| 658 | wgs84_ref.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); |
| 659 | #endif |
| 660 | poCT = OGRCreateCoordinateTransformation(spatial_ref, &wgs84_ref); |
| 661 | for (size_t i=0; i < ogr_geometries.size(); i++) { |
| 662 | ogr_geometries[i]->transform(poCT); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | // Start saving |
| 667 | int prog_n_max = 0; |
no test coverage detected