Skip to content

Commit ccb26da

Browse files
committed
Merge branch 'release/v5.3.0' into master
2 parents 25dc51e + eec2c13 commit ccb26da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+26910
-7539
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ support/GDAL_SDK/**/*.c
174174
support/GDAL_SDK/**/*.inc
175175
support/GDAL_SDK/**/*.proto
176176
support/GDAL_SDK/**/*.pc
177+
support/temp/
177178

178179
# Custom
179180
*.dll

src/COM classes/OgrLayer.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void COgrLayer::UpdateShapefileFromOGRLoader()
100100
{
101101
CSingleLock lock(&_loader.ProviderLock, TRUE);
102102
if (!_shapefile) return;
103+
lock.Unlock();
103104

104105
// Wait for tasks to finish loading:
105106
_loader.AwaitTasks();
@@ -110,9 +111,9 @@ void COgrLayer::UpdateShapefileFromOGRLoader()
110111
CSingleLock sfLock(&_loader.ShapefileLock, TRUE);
111112

112113
// Grab the loaded data:
113-
vector<ShapeRecordData*> data = _loader.FetchData();
114-
if (data.size() == 0)
114+
if (!_loader.HasData())
115115
return;
116+
vector<ShapeRecordData*> data = _loader.FetchData();
116117

117118
CStringW fid = OgrHelper::OgrString2Unicode(_layer->GetFIDColumn());
118119
bool hasFid = fid.GetLength() > 0;
@@ -861,9 +862,21 @@ STDMETHODIMP COgrLayer::SaveChanges(int* savedCount, tkOgrSaveType saveType, VAR
861862
}
862863

863864
{ // Locking provider & shapefile here
865+
CSingleLock loadingLock(&_loader.LoadingLock, _dynamicLoading ? TRUE : FALSE);
864866
CSingleLock lock(&_loader.ProviderLock, _dynamicLoading ? TRUE : FALSE);
865867
CSingleLock sfLock(&_loader.ShapefileLock, _dynamicLoading ? TRUE : FALSE);
866-
*savedCount = Shape2Ogr::SaveShapefileChanges(_layer, _shapefile, shapeCmnId, saveType, validateShapes ? true : false, _updateErrors);
868+
auto safeToDelete = true;
869+
if (_dynamicLoading)
870+
{
871+
VARIANT_BOOL hasFIDMap;
872+
_shapefile->get_HasOgrFidMapping(&hasFIDMap);
873+
if (!hasFIDMap)
874+
safeToDelete = false; //don't delete when there's no FID map to track them
875+
}
876+
*savedCount = Shape2Ogr::SaveShapefileChanges(
877+
_layer, _shapefile, shapeCmnId,
878+
saveType, validateShapes ? true : false,
879+
safeToDelete, _updateErrors);
867880
}
868881

869882
HasLocalChanges(&hasChanges);

src/COM classes/Shape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ void CShape::get_LabelPosition(tkLabelPositioning method, double& x, double& y,
20832083
if (method == labelPositioning && orientation == labelOrientation)
20842084
{
20852085
x = labelX;
2086-
y = labelX;
2086+
y = labelY;
20872087
rotation = labelRotation;
20882088
return;
20892089
}

src/COM classes/Shapefile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ HRESULT CShapefile::CreateNewCore(BSTR ShapefileName, ShpfileType ShapefileType,
809809
}
810810
else
811811
{
812+
813+
((CTableClass*)_table)->InjectShapefile(this);
812814
_shpfiletype = ShapefileType;
813815
_isEditingShapes = true;
814816
_sourceType = sstInMemory;
@@ -880,6 +882,7 @@ HRESULT CShapefile::CreateNewCore(BSTR ShapefileName, ShpfileType ShapefileType,
880882
}
881883
else
882884
{
885+
((CTableClass*)_table)->InjectShapefile(this);
883886
_shpfileName = tmp_shpfileName;
884887
_shxfileName = tmp_shpfileName.Left(tmp_shpfileName.GetLength() - 3) + "shx";
885888
_dbffileName = tmp_shpfileName.Left(tmp_shpfileName.GetLength() - 3) + "dbf";

src/COM classes/Shapefile.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ class ATL_NO_VTABLE CShapefile :
314314
// OGR layers can lookup by fixed FID rather than ever-changing ShapeIndex
315315
// (Shape indices change when removing rows, and may change on OGR reload)
316316
std::map<long, long> _ogrFid2ShapeIndex;
317+
std::set<long> _deletedFids;
317318
bool _hasOgrFidMapping = false;
318319

319320
// table is initialized in CreateNew or Open methods
@@ -503,6 +504,23 @@ class ATL_NO_VTABLE CShapefile :
503504
{
504505
_ogrFid2ShapeIndex.insert(std::make_pair(ogrFid, shapeIndex));
505506
}
507+
bool MarkShapeDeleted(long shapeIndex)
508+
{
509+
if (!_hasOgrFidMapping)
510+
return false;
511+
512+
for (auto const& it : _ogrFid2ShapeIndex)
513+
if (it.second == shapeIndex)
514+
_deletedFids.insert(it.first);
515+
}
516+
std::set<long> GetDeletedShapeFIDs()
517+
{
518+
return std::set<long>(_deletedFids);
519+
}
520+
void ClearDeleteShapeFIDs()
521+
{
522+
_deletedFids.clear();
523+
}
506524

507525
// give OGR layers the ability to retain visibility flags on reload
508526
bool GetVisibilityFlags(map<long, BYTE> &flags);

src/COM classes/ShapefileCategories.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,11 @@ void CShapefileCategories::ApplyExpressionCore(long CategoryIndex, long startRow
617617
// Saving results
618618
// -------------------------------------------------------------
619619
for (unsigned long i = 0; i < results.size(); i++) {
620-
// Is this a category we need?
621-
if (!allCategories && i != CategoryIndex)
620+
// Is this a category we need?
621+
const int categoryIndex = results[i];
622+
if (!allCategories && categoryIndex != CategoryIndex)
622623
continue;
623624

624-
const int categoryIndex = results[i];
625625
const int rowIndex = startRowIndex + i;
626626
_shapefile->put_ShapeCategory(rowIndex, categoryIndex);
627627
_shapefile->put_ShapeRotation(rowIndex, rotations[categoryIndex + 1][i]);

src/COM classes/Shapefile_Selection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ bool CShapefile::SelectShapesCore(Extent& extents, double Tolerance, SelectMode
183183
get_Shape(shapeVal, &shape);
184184
// convert querying shape to GEOS
185185
GEOSGeom geosShape = GeosConverter::ShapeToGeom(shape);
186+
if (geosShape == nullptr)
187+
continue;
186188
// check for containment
187189
if (GeosHelper::Contains(geosShape, geosPoint))
188190
{

src/COM classes/TableClass.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Field.h"
3030
#include "TableHelper.h"
3131
#include "FieldHelper.h"
32+
#include "Shapefile.h"
3233

3334
#pragma warning(disable:4996)
3435

@@ -717,6 +718,9 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
717718
return false;
718719
}
719720

721+
// is the Shapefile UTF-8 (if unspecified or specified as UTF-8)
722+
bool isUTF8 = (DBFGetCodePage(_dbfHandle) == nullptr || strcmp(DBFGetCodePage(_dbfHandle), "UTF-8") == 0);
723+
720724
// joined fields must be removed; they will be restored in the process of reopening table
721725
// after saving operation
722726
this->RemoveJoinedFields();
@@ -798,7 +802,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
798802
continue;
799803
}
800804

801-
if (!WriteRecord(newdbfHandle, rowIndex, ++currentRowIndex))
805+
if (!WriteRecord(newdbfHandle, rowIndex, ++currentRowIndex, isUTF8))
802806
{
803807
ErrorMessage(tkDBF_CANT_WRITE_ROW);
804808
return false;
@@ -934,6 +938,8 @@ void CTableClass::LoadDefaultFields()
934938
field->put_Width(fwidth);
935939
field->put_Precision(fdecimals);
936940
field->put_Type((FieldType)type);
941+
//// field has not really been modified
942+
//((CField*)field)->SetIsUpdated(false);
937943

938944
FieldWrapper* fw = new FieldWrapper();
939945
fw->oldIndex = i;
@@ -1439,7 +1445,7 @@ bool CTableClass::ReadRecord(long RowIndex)
14391445
// WriteRecord()
14401446
// *******************************************************************
14411447
//Write a cached RecordWrapper into dbf file
1442-
bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex)
1448+
bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8)
14431449
{
14441450
AFX_MANAGE_STATE(AfxGetStaticModuleState())
14451451
USES_CONVERSION;
@@ -1453,7 +1459,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14531459
if (fromRowIndex < 0 || fromRowIndex >= RowCount())
14541460
return false;
14551461

1456-
char * nonstackString = NULL;
1462+
const char * nonstackString = NULL;
14571463

14581464
for (long i = 0; i < FieldCount(); i++)
14591465
{
@@ -1467,7 +1473,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14671473
{
14681474
if (val.vt == VT_BSTR)
14691475
{
1470-
nonstackString = Utility::SYS2A(val.bstrVal);
1476+
nonstackString = Utility::ConvertBSTRToLPSTR(val.bstrVal, (isUTF8 ? CP_UTF8 : CP_ACP)); // ((LPCSTR)Utility::ConvertToUtf8(val.bstrVal)); // Utility::SYS2A(val.bstrVal);
14711477
DBFWriteStringAttribute(dbfHandle, toRowIndex, i, nonstackString);
14721478
delete[] nonstackString;
14731479
nonstackString = NULL;
@@ -1991,6 +1997,8 @@ STDMETHODIMP CTableClass::EditDeleteRow(long RowIndex, VARIANT_BOOL *retval)
19911997
AFX_MANAGE_STATE(AfxGetStaticModuleState())
19921998
*retval = VARIANT_FALSE;
19931999

2000+
((CShapefile*) _shapefile)->MarkShapeDeleted(RowIndex);
2001+
19942002
if (_isEditingTable == FALSE)
19952003
{
19962004
ErrorMessage(tkDBF_NOT_IN_EDIT_MODE);

src/COM classes/TableClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class ATL_NO_VTABLE CTableClass :
206206
long RowCount() { return _rows.size(); }
207207
long FieldCount() { return _fields.size(); }
208208
bool ReadRecord(long RowIndex);
209-
bool WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex);
209+
bool WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8 = false);
210210
void ClearRow(long rowIndex);
211211
FieldType GetFieldType(long fieldIndex);
212212
long GetFieldPrecision(long fieldIndex);

src/COM classes/Utils_GDAL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4342,7 +4342,11 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename,
43424342
&& (pszMethod == NULL || EQUALN(pszMethod,"GCP_",4)) )
43434343
pszThisSourceSRS = GDALGetGCPProjection( hSrcDS );
43444344
else if( pszMethod != NULL && EQUAL(pszMethod,"RPC") )
4345-
pszThisSourceSRS = SRS_WKT_WGS84;
4345+
#if GDAL_VERSION_MAJOR >= 3
4346+
pszThisSourceSRS = SRS_WKT_WGS84_LAT_LONG; // SRS_WKT_WGS84 macro is no longer declared by default since WKT without AXIS is too ambiguous. Preferred remediation: use SRS_WKT_WGS84_LAT_LONG
4347+
#else
4348+
pszThisSourceSRS = SRS_WKT_WGS84;
4349+
#endif
43464350
else
43474351
pszThisSourceSRS = "";
43484352
}

0 commit comments

Comments
 (0)