aboutsummaryrefslogtreecommitdiff
path: root/scripts/create_c_api_projections.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/create_c_api_projections.py')
-rwxr-xr-xscripts/create_c_api_projections.py55
1 files changed, 41 insertions, 14 deletions
diff --git a/scripts/create_c_api_projections.py b/scripts/create_c_api_projections.py
index 5d10a16b..a56e99b3 100755
--- a/scripts/create_c_api_projections.py
+++ b/scripts/create_c_api_projections.py
@@ -56,6 +56,21 @@ cppfile.write("\n");
test_cppfile.write("/* BEGIN: Generated by scripts/create_c_api_projections.py*/\n")
+def snake_casify(s):
+ out = ''
+ lastWasLowerAlpha = False
+ for c in s:
+ if c.isupper():
+ if lastWasLowerAlpha:
+ out += '_'
+ out += c.lower()
+ lastWasLowerAlpha = False
+ else:
+ out += c
+ lastWasLowerAlpha = c.isalpha()
+ return out
+
+
for sectiondef in compounddef.iter('sectiondef'):
if sectiondef.attrib['kind'] == 'public-static-func':
for func in sectiondef.iter('memberdef'):
@@ -79,22 +94,31 @@ for sectiondef in compounddef.iter('sectiondef'):
params.append((type, paramname))
shortName = name[len('create'):]
+ c_shortName = snake_casify(shortName)
- decl = "proj_obj_create_projected_crs_"
- decl += shortName
+ decl = "proj_obj_create_conversion_"
+ decl += c_shortName
decl += "(\n"
- decl += " PJ_OBJ* geodetic_crs, const char* crs_name,\n"
+ decl += " PJ_CONTEXT *ctx,\n"
+ has_output_params = False
for param in params:
+ if has_output_params:
+ decl += ",\n"
+
if param[0] in ('int', 'bool'):
- decl += " int " + param[1] + ",\n"
+ decl += " int " + param[1]
else:
- decl += " double " + param[1] + ",\n"
+ decl += " double " + param[1]
+ has_output_params = True
+
if has_angle:
+ if has_output_params:
+ decl += ",\n"
decl += " const char* angUnitName, double angUnitConvFactor"
- if has_linear:
- decl += ","
- decl += "\n"
+ has_output_params = True
if has_linear:
+ if has_output_params:
+ decl += ",\n"
decl += " const char* linearUnitName, double linearUnitConvFactor"
decl += ")"
@@ -113,9 +137,8 @@ for sectiondef in compounddef.iter('sectiondef'):
cppfile.write(" * Angular parameters are expressed in (angUnitName, angUnitConvFactor).\n")
cppfile.write(" */\n")
cppfile.write("PJ_OBJ* " + decl + "{\n");
- if not has_linear:
- cppfile.write(" const auto& linearUnit = UnitOfMeasure::METRE;\n")
- else:
+ cppfile.write(" try {\n");
+ if has_linear:
cppfile.write(" UnitOfMeasure linearUnit(createLinearUnit(linearUnitName, linearUnitConvFactor));\n")
if has_angle:
cppfile.write(" UnitOfMeasure angUnit(createAngularUnit(angUnitName, angUnitConvFactor));\n")
@@ -133,12 +156,16 @@ for sectiondef in compounddef.iter('sectiondef'):
cppfile.write(", Scale(" + param[1] + ")")
cppfile.write(");\n")
- cppfile.write(" return proj_obj_create_projected_crs(geodetic_crs, crs_name, conv, linearUnit);\n")
+ cppfile.write(" return proj_obj_create_conversion(ctx, conv);\n")
+ cppfile.write(" } catch (const std::exception &e) {\n");
+ cppfile.write(" proj_log_error(ctx, __FUNCTION__, e.what());\n")
+ cppfile.write(" }\n")
+ cppfile.write(" return nullptr;\n")
cppfile.write("}\n")
test_cppfile.write("{\n")
- test_cppfile.write(" auto projCRS = proj_obj_create_projected_crs_" + shortName + "(\n")
- test_cppfile.write(" geogCRS, nullptr")
+ test_cppfile.write(" auto projCRS = proj_obj_create_conversion_" + c_shortName + "(\n")
+ test_cppfile.write(" m_ctxt")
for param in params:
test_cppfile.write(", 0")
if has_angle: