@@ -433,7 +433,7 @@ OGRFeatureDefnH OGR_F_GetDefnRef(OGRFeatureH hFeat)
433
433
/* *
434
434
* \brief Set feature geometry.
435
435
*
436
- * This method updates the features geometry, and operate exactly as
436
+ * This method updates the features geometry, and operates the same as
437
437
* SetGeometry(), except that this method assumes ownership of the
438
438
* passed geometry (even in case of failure of that function).
439
439
*
@@ -456,11 +456,12 @@ OGRFeatureDefnH OGR_F_GetDefnRef(OGRFeatureH hFeat)
456
456
OGRErr OGRFeature::SetGeometryDirectly (OGRGeometry *poGeomIn)
457
457
458
458
{
459
- if (GetGeomFieldCount () > 0 )
460
- return SetGeomFieldDirectly (0 , poGeomIn);
459
+ if (poGeomIn == GetGeometryRef ())
460
+ {
461
+ return OGRERR_NONE;
462
+ }
461
463
462
- delete poGeomIn;
463
- return OGRERR_FAILURE;
464
+ return SetGeomField (0 , std::unique_ptr<OGRGeometry>(poGeomIn));
464
465
}
465
466
466
467
/* ***********************************************************************/
@@ -470,7 +471,7 @@ OGRErr OGRFeature::SetGeometryDirectly(OGRGeometry *poGeomIn)
470
471
/* *
471
472
* \brief Set feature geometry.
472
473
*
473
- * This function updates the features geometry, and operate exactly as
474
+ * This function updates the features geometry, and operates the same as
474
475
* SetGeometry(), except that this function assumes ownership of the
475
476
* passed geometry (even in case of failure of that function).
476
477
*
@@ -506,7 +507,7 @@ OGRErr OGR_F_SetGeometryDirectly(OGRFeatureH hFeat, OGRGeometryH hGeom)
506
507
/* *
507
508
* \brief Set feature geometry.
508
509
*
509
- * This method updates the features geometry, and operate exactly as
510
+ * This method updates the features geometry, and operates the same as
510
511
* SetGeometryDirectly(), except that this method does not assume ownership
511
512
* of the passed geometry, but instead makes a copy of it.
512
513
*
@@ -542,7 +543,7 @@ OGRErr OGRFeature::SetGeometry(const OGRGeometry *poGeomIn)
542
543
/* *
543
544
* \brief Set feature geometry.
544
545
*
545
- * This function updates the features geometry, and operate exactly as
546
+ * This function updates the features geometry, and operates the same as
546
547
* SetGeometryDirectly(), except that this function does not assume ownership
547
548
* of the passed geometry, but instead makes a copy of it.
548
549
*
@@ -570,6 +571,37 @@ OGRErr OGR_F_SetGeometry(OGRFeatureH hFeat, OGRGeometryH hGeom)
570
571
OGRGeometry::FromHandle (hGeom));
571
572
}
572
573
574
+ /* ***********************************************************************/
575
+ /* SetGeometry() */
576
+ /* ***********************************************************************/
577
+
578
+ /* *
579
+ * \brief Set feature geometry.
580
+ *
581
+ * This method is the same as the C function OGR_F_SetGeometryDirectly().
582
+ *
583
+ * @note This method has only an effect on the in-memory feature object. If
584
+ * this object comes from a layer and the modifications must be serialized back
585
+ * to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is
586
+ * a new feature, OGR_L_CreateFeature() must be used afterwards.
587
+ *
588
+ * @param poGeomIn new geometry to apply to feature. Passing NULL value here
589
+ * is correct and it will result in deallocation of currently assigned geometry
590
+ * without assigning new one.
591
+ *
592
+ * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if
593
+ * the geometry type is illegal for the OGRFeatureDefn (checking not yet
594
+ * implemented).
595
+ *
596
+ * @since GDAL 3.11
597
+ */
598
+
599
+ OGRErr OGRFeature::SetGeometry (std::unique_ptr<OGRGeometry> poGeomIn)
600
+
601
+ {
602
+ return SetGeomField (0 , std::move (poGeomIn));
603
+ }
604
+
573
605
/* ***********************************************************************/
574
606
/* StealGeometry() */
575
607
/* ***********************************************************************/
@@ -907,7 +939,7 @@ OGRGeometryH OGR_F_GetGeomFieldRef(OGRFeatureH hFeat, int iField)
907
939
/* *
908
940
* \brief Set feature geometry of a specified geometry field.
909
941
*
910
- * This method updates the features geometry, and operate exactly as
942
+ * This method updates the features geometry, and operates the same as
911
943
* SetGeomField(), except that this method assumes ownership of the
912
944
* passed geometry (even in case of failure of that function).
913
945
*
@@ -926,21 +958,13 @@ OGRGeometryH OGR_F_GetGeomFieldRef(OGRFeatureH hFeat, int iField)
926
958
*/
927
959
928
960
OGRErr OGRFeature::SetGeomFieldDirectly (int iField, OGRGeometry *poGeomIn)
929
-
930
961
{
931
- if (iField < 0 || iField >= GetGeomFieldCount ())
932
- {
933
- delete poGeomIn;
934
- return OGRERR_FAILURE;
935
- }
936
-
937
- if (papoGeometries[iField] != poGeomIn)
962
+ if (poGeomIn && poGeomIn == GetGeomFieldRef (iField))
938
963
{
939
- delete papoGeometries[iField];
940
- papoGeometries[iField] = poGeomIn;
964
+ return OGRERR_NONE;
941
965
}
942
966
943
- return OGRERR_NONE ;
967
+ return SetGeomField (iField, std::unique_ptr<OGRGeometry>(poGeomIn)) ;
944
968
}
945
969
946
970
/* ***********************************************************************/
@@ -950,7 +974,7 @@ OGRErr OGRFeature::SetGeomFieldDirectly(int iField, OGRGeometry *poGeomIn)
950
974
/* *
951
975
* \brief Set feature geometry of a specified geometry field.
952
976
*
953
- * This function updates the features geometry, and operate exactly as
977
+ * This function updates the features geometry, and operates the same as
954
978
* SetGeomField(), except that this function assumes ownership of the
955
979
* passed geometry (even in case of failure of that function).
956
980
*
@@ -985,7 +1009,7 @@ OGRErr OGR_F_SetGeomFieldDirectly(OGRFeatureH hFeat, int iField,
985
1009
/* *
986
1010
* \brief Set feature geometry of a specified geometry field.
987
1011
*
988
- * This method updates the features geometry, and operate exactly as
1012
+ * This method updates the features geometry, and operates the same as
989
1013
* SetGeomFieldDirectly(), except that this method does not assume ownership
990
1014
* of the passed geometry, but instead makes a copy of it.
991
1015
*
@@ -1031,7 +1055,7 @@ OGRErr OGRFeature::SetGeomField(int iField, const OGRGeometry *poGeomIn)
1031
1055
/* *
1032
1056
* \brief Set feature geometry of a specified geometry field.
1033
1057
*
1034
- * This function updates the features geometry, and operate exactly as
1058
+ * This function updates the features geometry, and operates the same as
1035
1059
* SetGeometryDirectly(), except that this function does not assume ownership
1036
1060
* of the passed geometry, but instead makes a copy of it.
1037
1061
*
@@ -1055,6 +1079,45 @@ OGRErr OGR_F_SetGeomField(OGRFeatureH hFeat, int iField, OGRGeometryH hGeom)
1055
1079
iField, OGRGeometry::FromHandle (hGeom));
1056
1080
}
1057
1081
1082
+ /* ***********************************************************************/
1083
+ /* SetGeomField() */
1084
+ /* ***********************************************************************/
1085
+
1086
+ /* *
1087
+ * \brief Set feature geometry of a specified geometry field.
1088
+ *
1089
+ * This method is the same as the C function OGR_F_SetGeomFieldDirectly().
1090
+ *
1091
+ * @param iField geometry field to set.
1092
+ * @param poGeomIn new geometry to apply to feature. Passing NULL value here
1093
+ * is correct and it will result in deallocation of currently assigned geometry
1094
+ * without assigning new one.
1095
+ *
1096
+ * @return OGRERR_NONE if successful, or OGRERR_FAILURE if the index is invalid,
1097
+ * or OGRERR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the
1098
+ * OGRFeatureDefn (checking not yet implemented).
1099
+ *
1100
+ * @since GDAL 3.11
1101
+ */
1102
+
1103
+ OGRErr OGRFeature::SetGeomField (int iField,
1104
+ std::unique_ptr<OGRGeometry> poGeomIn)
1105
+
1106
+ {
1107
+ if (iField < 0 || iField >= GetGeomFieldCount ())
1108
+ {
1109
+ return OGRERR_FAILURE;
1110
+ }
1111
+
1112
+ if (papoGeometries[iField] != poGeomIn.get ())
1113
+ {
1114
+ delete papoGeometries[iField];
1115
+ papoGeometries[iField] = poGeomIn.release ();
1116
+ }
1117
+
1118
+ return OGRERR_NONE;
1119
+ }
1120
+
1058
1121
/* ***********************************************************************/
1059
1122
/* Clone() */
1060
1123
/* ***********************************************************************/
@@ -6688,7 +6751,7 @@ const char *OGR_F_GetStyleString(OGRFeatureH hFeat)
6688
6751
/* *
6689
6752
* \brief Set feature style string.
6690
6753
*
6691
- * This method operate exactly as OGRFeature::SetStyleStringDirectly() except
6754
+ * This method operates the same as OGRFeature::SetStyleStringDirectly() except
6692
6755
* that it does not assume ownership of the passed string, but instead makes a
6693
6756
* copy of it.
6694
6757
*
@@ -6716,7 +6779,7 @@ void OGRFeature::SetStyleString(const char *pszString)
6716
6779
/* *
6717
6780
* \brief Set feature style string.
6718
6781
*
6719
- * This method operate exactly as OGR_F_SetStyleStringDirectly() except that it
6782
+ * This method operates the same as OGR_F_SetStyleStringDirectly() except that it
6720
6783
* does not assume ownership of the passed string, but instead makes a copy of
6721
6784
* it.
6722
6785
*
@@ -6741,7 +6804,7 @@ void OGR_F_SetStyleString(OGRFeatureH hFeat, const char *pszStyle)
6741
6804
/* *
6742
6805
* \brief Set feature style string.
6743
6806
*
6744
- * This method operate exactly as OGRFeature::SetStyleString() except that it
6807
+ * This method operates the same as OGRFeature::SetStyleString() except that it
6745
6808
* assumes ownership of the passed string.
6746
6809
*
6747
6810
* This method is the same as the C function OGR_F_SetStyleStringDirectly().
@@ -6762,7 +6825,7 @@ void OGRFeature::SetStyleStringDirectly(char *pszString)
6762
6825
/* *
6763
6826
* \brief Set feature style string.
6764
6827
*
6765
- * This method operate exactly as OGR_F_SetStyleString() except that it assumes
6828
+ * This method operates the same as OGR_F_SetStyleString() except that it assumes
6766
6829
* ownership of the passed string.
6767
6830
*
6768
6831
* This function is the same as the C++ method
0 commit comments