From b64e863a8d86bcc984867c2be19df6637b77e6b1 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 30 Jan 2025 10:24:24 +0100 Subject: [PATCH] Remove OGR Geoconcept export driver --- .../ubuntu_24.04/expected_ogrinfo_formats.txt | 1 - ...windows_conda_expected_ogrinfo_formats.txt | 1 - .../ogr/data/geoconcept/expected_000_GRD.gxt | 17 - .../ogr/data/geoconcept/expected_000_GRD.txt | 12 - .../data/geoconcept/expected_000_GRD_TAB.txt | 12 - .../ogr/data/geoconcept/expected_tile.gxt | 17 - .../ogr/data/geoconcept/expected_tile.txt | 12 - ...eoconcept_multipolygon_singlepart_hole.txt | 8 - ...concept_multipolygon_singlepart_nohole.txt | 8 - ...multipolygon_twoparts_second_with_hole.txt | 8 - autotest/ogr/data/geoconcept/line.gxt | 8 - autotest/ogr/data/geoconcept/points.gxt | 9 - autotest/ogr/ogr_geoconcept.py | 256 - doc/source/drivers/vector/geoconcept.rst | 288 - doc/source/drivers/vector/index.rst | 1 - ogr/ogrsf_frmts/CMakeLists.txt | 1 - ogr/ogrsf_frmts/generic/ogrregisterall.cpp | 3 - ogr/ogrsf_frmts/geoconcept/CMakeLists.txt | 17 - ogr/ogrsf_frmts/geoconcept/geoconcept.c | 5623 ----------------- ogr/ogrsf_frmts/geoconcept/geoconcept.h | 539 -- .../geoconcept/geoconcept_syscoord.c | 1213 ---- .../geoconcept/geoconcept_syscoord.h | 186 - .../geoconcept/ogrgeoconceptdatasource.cpp | 542 -- .../geoconcept/ogrgeoconceptdatasource.h | 62 - .../geoconcept/ogrgeoconceptdriver.cpp | 219 - .../geoconcept/ogrgeoconceptlayer.cpp | 658 -- .../geoconcept/ogrgeoconceptlayer.h | 80 - ogr/ogrsf_frmts/ogrsf_frmts.h | 1 - 28 files changed, 9802 deletions(-) delete mode 100644 autotest/ogr/data/geoconcept/expected_000_GRD.gxt delete mode 100644 autotest/ogr/data/geoconcept/expected_000_GRD.txt delete mode 100644 autotest/ogr/data/geoconcept/expected_000_GRD_TAB.txt delete mode 100644 autotest/ogr/data/geoconcept/expected_tile.gxt delete mode 100644 autotest/ogr/data/geoconcept/expected_tile.txt delete mode 100644 autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_hole.txt delete mode 100644 autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_nohole.txt delete mode 100644 autotest/ogr/data/geoconcept/geoconcept_multipolygon_twoparts_second_with_hole.txt delete mode 100644 autotest/ogr/data/geoconcept/line.gxt delete mode 100644 autotest/ogr/data/geoconcept/points.gxt delete mode 100755 autotest/ogr/ogr_geoconcept.py delete mode 100644 doc/source/drivers/vector/geoconcept.rst delete mode 100644 ogr/ogrsf_frmts/geoconcept/CMakeLists.txt delete mode 100644 ogr/ogrsf_frmts/geoconcept/geoconcept.c delete mode 100644 ogr/ogrsf_frmts/geoconcept/geoconcept.h delete mode 100644 ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c delete mode 100644 ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.h delete mode 100644 ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.cpp delete mode 100644 ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.h delete mode 100644 ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdriver.cpp delete mode 100644 ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp delete mode 100644 ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.h diff --git a/.github/workflows/ubuntu_24.04/expected_ogrinfo_formats.txt b/.github/workflows/ubuntu_24.04/expected_ogrinfo_formats.txt index 053c150f30ab..5bbfab2ee75b 100644 --- a/.github/workflows/ubuntu_24.04/expected_ogrinfo_formats.txt +++ b/.github/workflows/ubuntu_24.04/expected_ogrinfo_formats.txt @@ -44,7 +44,6 @@ Supported Formats: (ro:read-only, rw:read-write, +:update, v:virtual-I/O s:subda DXF -vector- (rw+v): AutoCAD DXF (*.dxf) CAD -raster,vector- (rovs): AutoCAD Driver (*.dwg) FlatGeobuf -vector- (rw+v): FlatGeobuf (*.fgb) - Geoconcept -vector- (rw+v): Geoconcept (*.gxt, *.txt) GeoRSS -vector- (rw+v): GeoRSS VFK -vector- (ro): Czech Cadastral Exchange Data Format (*.vfk) PGDUMP -vector- (w+v): PostgreSQL SQL dump (*.sql) diff --git a/.github/workflows/windows_conda_expected_ogrinfo_formats.txt b/.github/workflows/windows_conda_expected_ogrinfo_formats.txt index 744a9af312b4..2d6bcb61fcba 100644 --- a/.github/workflows/windows_conda_expected_ogrinfo_formats.txt +++ b/.github/workflows/windows_conda_expected_ogrinfo_formats.txt @@ -41,7 +41,6 @@ Supported Formats: (ro:read-only, rw:read-write, +:update, v:virtual-I/O s:subda DXF -vector- (rw+v): AutoCAD DXF (*.dxf) CAD -raster,vector- (rovs): AutoCAD Driver (*.dwg) FlatGeobuf -vector- (rw+v): FlatGeobuf (*.fgb) - Geoconcept -vector- (rw+v): Geoconcept (*.gxt, *.txt) GeoRSS -vector- (rw+v): GeoRSS VFK -vector- (ro): Czech Cadastral Exchange Data Format (*.vfk) PGDUMP -vector- (w+v): PostgreSQL SQL dump (*.sql) diff --git a/autotest/ogr/data/geoconcept/expected_000_GRD.gxt b/autotest/ogr/data/geoconcept/expected_000_GRD.gxt deleted file mode 100644 index d017b5c01651..000000000000 --- a/autotest/ogr/data/geoconcept/expected_000_GRD.gxt +++ /dev/null @@ -1,17 +0,0 @@ -//$DELIMITER " " -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 1006} -//$FIELDS Class=000_GRD;Subclass=000_GRD;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields idSel nom withdata Private#X Private#Y Private#Graphics --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 diff --git a/autotest/ogr/data/geoconcept/expected_000_GRD.txt b/autotest/ogr/data/geoconcept/expected_000_GRD.txt deleted file mode 100644 index 400068e26566..000000000000 --- a/autotest/ogr/data/geoconcept/expected_000_GRD.txt +++ /dev/null @@ -1,12 +0,0 @@ -//$DELIMITER " " -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 1006} -//$FIELDS Class=000_GRD;Subclass=000_GRD;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields idSel nom withdata Private#X Private#Y Private#Graphics --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 diff --git a/autotest/ogr/data/geoconcept/expected_000_GRD_TAB.txt b/autotest/ogr/data/geoconcept/expected_000_GRD_TAB.txt deleted file mode 100644 index 122f2d4ff3a1..000000000000 --- a/autotest/ogr/data/geoconcept/expected_000_GRD_TAB.txt +++ /dev/null @@ -1,12 +0,0 @@ -//$DELIMITER "tab" -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 1006} -//$FIELDS Class=000_GRD;Subclass=000_GRD;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields idSel nom withdata Private#X Private#Y Private#Graphics --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 000_GRD 000_GRD 000_GRD 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 diff --git a/autotest/ogr/data/geoconcept/expected_tile.gxt b/autotest/ogr/data/geoconcept/expected_tile.gxt deleted file mode 100644 index 52148b65072c..000000000000 --- a/autotest/ogr/data/geoconcept/expected_tile.gxt +++ /dev/null @@ -1,17 +0,0 @@ -//$DELIMITER " " -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 2001} -//$FIELDS Class=TILE;Subclass=TILE;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields IDSEL NOM WITHDATA Private#X Private#Y Private#Graphics --1 TILE TILE TILE 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 TILE TILE TILE 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 TILE TILE TILE 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 --1 TILE TILE TILE 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 TILE TILE TILE 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 TILE TILE TILE 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 diff --git a/autotest/ogr/data/geoconcept/expected_tile.txt b/autotest/ogr/data/geoconcept/expected_tile.txt deleted file mode 100644 index 86e5636d9b45..000000000000 --- a/autotest/ogr/data/geoconcept/expected_tile.txt +++ /dev/null @@ -1,12 +0,0 @@ -//$DELIMITER " " -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 2001} -//$FIELDS Class=TILE;Subclass=TILE;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields IDSEL NOM WITHDATA Private#X Private#Y Private#Graphics --1 TILE TILE TILE 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 --1 TILE TILE TILE 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 --1 TILE TILE TILE 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 --1 TILE TILE TILE 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 diff --git a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_hole.txt b/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_hole.txt deleted file mode 100644 index 9c2410d32929..000000000000 --- a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_hole.txt +++ /dev/null @@ -1,8 +0,0 @@ -//$DELIMITER "tab" -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 17};{TimeZone: 31} -//$FIELDS Class=test;Subclass=test;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields id Private#X Private#Y Private#Graphics --1 test test test 1 1 0.00 0.00 4 0.00 1.00 1.00 1.00 1.00 0.00 0.00 0.00 1 0.10 0.10 3 0.10 0.90 0.90 0.90 0.10 0.10 diff --git a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_nohole.txt b/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_nohole.txt deleted file mode 100644 index e5f2595c75d3..000000000000 --- a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_singlepart_nohole.txt +++ /dev/null @@ -1,8 +0,0 @@ -//$DELIMITER "tab" -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 17};{TimeZone: 31} -//$FIELDS Class=test;Subclass=test;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields id Private#X Private#Y Private#Graphics --1 test test test 1 1 0.00 0.00 4 0.00 1.00 1.00 1.00 1.00 0.00 0.00 0.00 diff --git a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_twoparts_second_with_hole.txt b/autotest/ogr/data/geoconcept/geoconcept_multipolygon_twoparts_second_with_hole.txt deleted file mode 100644 index 2348ee1ca0fb..000000000000 --- a/autotest/ogr/data/geoconcept/geoconcept_multipolygon_twoparts_second_with_hole.txt +++ /dev/null @@ -1,8 +0,0 @@ -//$DELIMITER "tab" -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 17};{TimeZone: 31} -//$FIELDS Class=test;Subclass=test;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields id Private#X Private#Y Private#Graphics --1 test test test 1 1 -10.00 -10.00 3 -10.00 -9.00 -9.00 -9.00 -10.00 -10.00 2 0.00 0.00 4 0.00 1.00 1.00 1.00 1.00 0.00 0.00 0.00 0.10 0.10 3 0.10 0.90 0.90 0.90 0.10 0.10 diff --git a/autotest/ogr/data/geoconcept/line.gxt b/autotest/ogr/data/geoconcept/line.gxt deleted file mode 100644 index 2704eb583864..000000000000 --- a/autotest/ogr/data/geoconcept/line.gxt +++ /dev/null @@ -1,8 +0,0 @@ -//$DELIMITER "tab" -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 17};{TimeZone: 31} -//$FIELDS Class=test;Subclass=test;Kind=2;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields id Private#X Private#Y Private#XP Private#YP Private#Graphics --1 test test test 1 1 440720.00 3751320.00 441920.00 3750120.00 1 441920.00 3750120.00 diff --git a/autotest/ogr/data/geoconcept/points.gxt b/autotest/ogr/data/geoconcept/points.gxt deleted file mode 100644 index b28ef1b3de6b..000000000000 --- a/autotest/ogr/data/geoconcept/points.gxt +++ /dev/null @@ -1,9 +0,0 @@ -//$DELIMITER " " -//$QUOTED-TEXT "no" -//$CHARSET ANSI -//$UNIT Distance:m -//$FORMAT 2 -//$SYSCOORD {Type: 101} -//$FIELDS Class=points;Subclass=points;Kind=1;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields Primary_ID Secondary_ID Third_ID Private#X Private#Y --1 points points points 3 PID1 SID1 TID1 0 1 --1 points points points 3 PID2 SID2 2 3 diff --git a/autotest/ogr/ogr_geoconcept.py b/autotest/ogr/ogr_geoconcept.py deleted file mode 100755 index efac45717588..000000000000 --- a/autotest/ogr/ogr_geoconcept.py +++ /dev/null @@ -1,256 +0,0 @@ -#!/usr/bin/env pytest -############################################################################### -# -# Project: GDAL/OGR Test Suite -# Purpose: Test OGR Geoconcept driver functionality. -# Author: Frank Warmerdam -# -############################################################################### -# Copyright (c) 2008, Frank Warmerdam -# Copyright (c) 2008, Even Rouault -# -# SPDX-License-Identifier: MIT -############################################################################### - -import ogrtest -import pytest - -from osgeo import ogr, osr - -pytestmark = pytest.mark.require_driver("Geoconcept") - -############################################################################### - - -@pytest.fixture(autouse=True, scope="module") -def startup_and_cleanup(): - yield - - -############################################################################### -# Simple read test of known file. - - -def test_ogr_gxt_1(): - - ds = ogr.Open("data/geoconcept/expected_000_GRD.gxt") - - assert ds is not None - - assert ds.GetLayerCount() == 1, "Got wrong layer count." - - lyr = ds.GetLayer(0) - assert lyr.GetName() == "000_GRD.000_GRD", "got unexpected layer name." - - assert lyr.GetFeatureCount() == 10, "got wrong feature count." - - expect = [ - "000-2007-0050-7130-LAMB93", - "000-2007-0595-7130-LAMB93", - "000-2007-0595-6585-LAMB93", - "000-2007-1145-6250-LAMB93", - "000-2007-0050-6585-LAMB93", - "000-2007-0050-7130-LAMB93", - "000-2007-0595-7130-LAMB93", - "000-2007-0595-6585-LAMB93", - "000-2007-1145-6250-LAMB93", - "000-2007-0050-6585-LAMB93", - ] - - ogrtest.check_features_against_list(lyr, "idSel", expect) - - lyr.ResetReading() - - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "MULTIPOLYGON (((50000 7130000,600000 7130000,600000 6580000,50000 6580000,50000 7130000)))", - max_error=0.000000001, - ) - - srs = osr.SpatialReference() - srs.SetFromUserInput( - 'PROJCS["Lambert 93",GEOGCS["unnamed",DATUM["ITRS-89",SPHEROID["GRS 80",6378137,298.257222099657],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",44],PARAMETER["standard_parallel_2",49],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["metre",1]]' - ) - - assert lyr.GetSpatialRef().IsSame(srs), "SRS is not the one expected." - - -############################################################################### -# Similar test than previous one with TAB separator. - - -def test_ogr_gxt_2(): - - ds = ogr.Open("data/geoconcept/expected_000_GRD_TAB.txt") - - assert ds is not None - - assert ds.GetLayerCount() == 1, "Got wrong layer count." - - lyr = ds.GetLayer(0) - assert lyr.GetName() == "000_GRD.000_GRD", "got unexpected layer name." - - assert lyr.GetFeatureCount() == 5, "got wrong feature count." - - expect = [ - "000-2007-0050-7130-LAMB93", - "000-2007-0595-7130-LAMB93", - "000-2007-0595-6585-LAMB93", - "000-2007-1145-6250-LAMB93", - "000-2007-0050-6585-LAMB93", - ] - - ogrtest.check_features_against_list(lyr, "idSel", expect) - - lyr.ResetReading() - - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "MULTIPOLYGON (((50000 7130000,600000 7130000,600000 6580000,50000 6580000,50000 7130000)))", - max_error=0.000000001, - ) - - -############################################################################### -# Read a GXT file containing 2 points, duplicate it, and check the newly written file - - -def test_ogr_gxt_3(tmp_path): - - ds = None - - src_ds = ogr.Open("data/geoconcept/points.gxt") - - # Duplicate all the points from the source GXT - src_lyr = src_ds.GetLayerByName("points.points") - - ds = ogr.GetDriverByName("Geoconcept").CreateDataSource(tmp_path / "tmp.gxt") - - srs = osr.SpatialReference() - srs.SetWellKnownGeogCS("WGS84") - - gxt_lyr = ds.CreateLayer("points", srs, geom_type=ogr.wkbPoint) - - src_lyr.ResetReading() - - for i in range(src_lyr.GetLayerDefn().GetFieldCount()): - field_defn = src_lyr.GetLayerDefn().GetFieldDefn(i) - gxt_lyr.CreateField(field_defn) - - dst_feat = ogr.Feature(feature_def=gxt_lyr.GetLayerDefn()) - - feat = src_lyr.GetNextFeature() - while feat is not None: - dst_feat.SetFrom(feat) - assert gxt_lyr.CreateFeature(dst_feat) == 0, "CreateFeature failed." - - feat = src_lyr.GetNextFeature() - - ds = None - - # Read the newly written GXT file and check its features and geometries - ds = ogr.Open(tmp_path / "tmp.gxt") - gxt_lyr = ds.GetLayerByName("points.points") - - assert gxt_lyr.GetSpatialRef().IsSame( - srs, options=["IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES"] - ), "Output SRS is not the one expected." - - expect = ["PID1", "PID2"] - - ogrtest.check_features_against_list(gxt_lyr, "Primary_ID", expect) - - gxt_lyr.ResetReading() - - expect = ["SID1", "SID2"] - - ogrtest.check_features_against_list(gxt_lyr, "Secondary_ID", expect) - - gxt_lyr.ResetReading() - - expect = ["TID1", None] - - ogrtest.check_features_against_list(gxt_lyr, "Third_ID", expect) - - gxt_lyr.ResetReading() - - feat = gxt_lyr.GetNextFeature() - - ogrtest.check_feature_geometry(feat, "POINT(0 1)", max_error=0.000000001) - - feat = gxt_lyr.GetNextFeature() - - ogrtest.check_feature_geometry(feat, "POINT(2 3)", max_error=0.000000001) - - -############################################################################### -# - - -def test_ogr_gxt_multipolygon_singlepart_nohole(): - - ds = ogr.Open("data/geoconcept/geoconcept_multipolygon_singlepart_nohole.txt") - lyr = ds.GetLayer(0) - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, "MULTIPOLYGON (((0 0,0 1,1 1,1 0,0 0)))", max_error=0.000000001 - ) - - -############################################################################### -# - - -@pytest.mark.require_geos -def test_ogr_gxt_multipolygon_singlepart_hole(): - - ds = ogr.Open("data/geoconcept/geoconcept_multipolygon_singlepart_hole.txt") - lyr = ds.GetLayer(0) - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "MULTIPOLYGON (((0 0,0 1,1 1,1 0,0 0),(0.1 0.1,0.1 0.9,0.9 0.9,0.1 0.1)))", - max_error=0.000000001, - ) - - -############################################################################### -# - - -@pytest.mark.require_geos -def test_ogr_gxt_multipolygon_twoparts_second_with_hole(): - - ds = ogr.Open( - "data/geoconcept/geoconcept_multipolygon_twoparts_second_with_hole.txt" - ) - lyr = ds.GetLayer(0) - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "MULTIPOLYGON (((-10 -10,-10 -9,-9 -9,-10 -10)),((0 0,0 1,1 1,1 0,0 0),(0.1 0.1,0.1 0.9,0.9 0.9,0.1 0.1)))", - max_error=0.000000001, - ) - - -############################################################################### -# - - -@pytest.mark.require_geos -def test_ogr_gxt_line(): - - ds = ogr.Open("data/geoconcept/line.gxt") - lyr = ds.GetLayer(0) - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, "LINESTRING (440720 3751320,441920 3750120)", max_error=0.000000001 - ) diff --git a/doc/source/drivers/vector/geoconcept.rst b/doc/source/drivers/vector/geoconcept.rst deleted file mode 100644 index 59add3415efa..000000000000 --- a/doc/source/drivers/vector/geoconcept.rst +++ /dev/null @@ -1,288 +0,0 @@ -.. _vector.geoconcept: - -GeoConcept text export -====================== - -.. shortname:: Geoconcept - -.. built_in_by_default:: - -GeoConcept text export files should be available for writing and -reading. - -The OGR GeoConcept driver treats a single GeoConcept file within a -directory as a dataset comprising layers. GeoConcept files extensions -are ``.txt`` or ``.gxt``. - -Currently the GeoConcept driver only supports multi-polygons, lines and -points. - -Driver capabilities -------------------- - -.. supports_create:: - -.. supports_georeferencing:: - -.. supports_virtualio:: - -GeoConcept Text File Format (gxt) ---------------------------------- - -GeoConcept is a GIS developed by the Company GeoConcept SA. - -It's an object oriented GIS, where the features are named « objects », -and feature types are named « type/subtype » (class allowing -inheritance). - -Among its import/export formats, it proposes a simple text format named -gxt. A gxt file may contain objects from several type/subtype. - -GeoConcept text export files should be available for writing and -reading. - -The OGR GeoConcept driver treats a single GeoConcept file within a -directory as a dataset comprising layers. GeoConcept files extensions -are ``.txt`` or ``.gxt``. - -Currently the GeoConcept driver only supports multi-polygons, lines and -points. - -Creation Issues ---------------- - -The GeoConcept driver treats a GeoConcept file (``.txt`` or ``.gxt``) as -a dataset. - -GeoConcept files can store multiple kinds of geometry (one by layer), -even if a GeoConcept layer can only have one kind of geometry. - -Note this makes it very difficult to translate a mixed geometry layer -from another format into GeoConcept format using ogr2ogr, since ogr2ogr -has no support for separating out geometries from a source layer. - -GeoConcept sub-type is treated as OGR feature. The name of a layer is -therefore the concatenation of the GeoConcept type name, ``'.'`` and -GeoConcept sub-type name. - -GeoConcept type definition (``.gct`` files) are used for creation only. - -GeoConcept feature fields definition are stored in an associated -``.gct`` file, and so fields suffer a number of limitations (FIXME) : - -- Attribute names are not limited in length. -- Only Integer, Real and String field types are supported. The various - list, and other field types cannot be created for the moment (they - exist in the GeoConcept model, but are not yet supported by the - GeoConcept driver). - -The OGR GeoConcept driver does not support deleting features. - -Dataset Creation Options -~~~~~~~~~~~~~~~~~~~~~~~~ - -|about-dataset-creation-options| -The following dataset creation options are supported: - -- .. dsco:: EXTENSION - :choices: TXT, GXT - - indicates the GeoConcept export file extension. - ``TXT`` was used by earlier releases of GeoConcept. ``GXT`` is currently - used. - -- .. dsco:: CONFIG - :choices: - - the GCT file describe the GeoConcept types - definitions : In this file, every line must start with ``//#`` followed - by a keyword. Lines starting with ``//`` are comments. - - It is important to note that a GeoConcept export file can hold different - types and associated sub-types. - - - configuration section : the GCT file starts with - ``//#SECTION CONFIG`` and ends with ``//#ENDSECTION CONFIG``. All the - configuration is enclosed within these marks. - - map section : purely for documentation at the time of writing this - document. This section starts with ``//#SECTION MAP`` and ends with - ``//#ENDSECTION MAP``. - - type section : this section defines a class of features. A type has a - name (keyword ``Name``) and an ID (keyword ``ID``). A type holds - sub-types and fields. This section starts with ``//#SECTION TYPE`` - and ends with ``//#ENDSECTION TYPE``. - - - sub-type section : this sub-section defines a kind og features - within a class. A sub-type has a name (keyword ``Name``), an ID - (keyword ``ID``), a type of geometry (keyword ``Kind``) and a - dimension. The following types of geometry are supported : POINT, - LINE, POLYGON. The current release of this driver does not support - the TEXT geometry. The dimension can be 2D, 3DM or 3D. A sub-type - holds fields. This section starts with ``//#SECTION SUBTYPE`` and - ends with ``//#ENDSECTION SUBTYPE``. - - - fields section : defines user fields. A field has a name - (keyword ``Name``), an ID (keyword ``ID``), a type (keyword - ``Kind``). The following types of fields are supported : INT, - REAL, MEMO, CHOICE, DATE, TIME, LENGTH, AREA. This section - starts with ``//#SECTION FIELD`` and ends with - ``//#ENDSECTION FIELD``. - - - field section : defines type fields. See above. - - - field section : defines general fields. Out of these, the following - rules apply : - - - private field names start with a '@' : the private fields are - ``Identifier``, ``Class``, ``Subclass``, ``Name``, ``NbFields``, - ``X``, ``Y``, ``XP``, ``YP``, ``Graphics``, ``Angle``. - - some private field are mandatory (they must appear in the - configuration) : ``Identifier``, ``Class``, ``Subclass``, - ``Name``, ``X``, ``Y``. - - If the sub-type is linear (LINE), then the following fields must - be declared ``XP``, ``YP``. - - If the sub-type is linear or polygonal (LINE, POLY), then - ``Graphics`` must be declared. - - If the sub-type is ponctual or textual (POINT, TEXT), the - ``Angle`` may be declared. - - When this option is not used, the driver manage types and sub-types - name based on either the layer name or on the use of ``-nln`` option. - -Layer Creation Options -~~~~~~~~~~~~~~~~~~~~~~ - -|about-layer-creation-options| -The following layer creation options are supported: - -- .. lco:: FEATURETYPE - :choices: - - defines the feature to be created. The - ``TYPE`` corresponds to one of the ``Name`` found in the GCT file for a - type section. The ``SUBTYPE`` corresponds to one of the ``Name`` found - in the GCT file for a sub-type section within the previous type section. - -At the present moment, coordinates are written with 2 decimals for -Cartesian spatial reference systems (including height) or with 9 -decimals for geographical spatial reference systems. - -Examples -~~~~~~~~ - -Example of a .gct file : -^^^^^^^^^^^^^^^^^^^^^^^^ - -:: - - //#SECTION CONFIG - //#SECTION MAP - //# Name=SCAN1000-TILES-LAMB93 - //# Unit=m - //# Precision=1000 - //#ENDSECTION MAP - //#SECTION TYPE - //# Name=TILE - //# ID=10 - //#SECTION SUBTYPE - //# Name=TILE - //# ID=100 - //# Kind=POLYGON - //# 3D=2D - //#SECTION FIELD - //# Name=IDSEL - //# ID=101 - //# Kind=TEXT - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=NOM - //# ID=102 - //# Kind=TEXT - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=WITHDATA - //# ID=103 - //# Kind=INT - //#ENDSECTION FIELD - //#ENDSECTION SUBTYPE - //#ENDSECTION TYPE - //#SECTION FIELD - //# Name=@Identifier - //# ID=-1 - //# Kind=INT - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@Class - //# ID=-2 - //# Kind=CHOICE - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@Subclass - //# ID=-3 - //# Kind=CHOICE - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@Name - //# ID=-4 - //# Kind=TEXT - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@X - //# ID=-5 - //# Kind=REAL - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@Y - //# ID=-6 - //# Kind=REAL - //#ENDSECTION FIELD - //#SECTION FIELD - //# Name=@Graphics - //# ID=-7 - //# Kind=REAL - //#ENDSECTION FIELD - //#ENDSECTION CONFIG - -Example of a GeoConcept text export : -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -:: - - //$DELIMITER " " - //$QUOTED-TEXT "no" - //$CHARSET ANSI - //$UNIT Distance=m - //$FORMAT 2 - //$SYSCOORD {Type: 2001} - //$FIELDS Class=TILE;Subclass=TILE;Kind=4;Fields=Private#Identifier Private#Class Private#Subclass Private#Name Private#NbFields IDSEL NOM WITHDATA Private#X Private#Y Private#Graphics - -1 TILE TILE TILE 3 000-2007-0050-7130-LAMB93 0 50000.00 7130000.00 4 600000.00 7130000.00 600000.00 6580000.00 50000.00 6580000.00 50000.00 7130000.00 - -1 TILE TILE TILE 3 000-2007-0595-7130-LAMB93 0 595000.00 7130000.00 4 1145000.00 7130000.00 1145000.00 6580000.00 595000.00 6580000.00 595000.00 7130000.00 - -1 TILE TILE TILE 3 000-2007-0595-6585-LAMB93 0 595000.00 6585000.00 4 1145000.00 6585000.00 1145000.00 6035000.00 595000.00 6035000.00 595000.00 6585000.00 - -1 TILE TILE TILE 3 000-2007-1145-6250-LAMB93 0 1145000.00 6250000.00 4 1265000.00 6250000.00 1265000.00 6030000.00 1145000.00 6030000.00 1145000.00 6250000.00 - -1 TILE TILE TILE 3 000-2007-0050-6585-LAMB93 0 50000.00 6585000.00 4 600000.00 6585000.00 600000.00 6035000.00 50000.00 6035000.00 50000.00 6585000.00 - -Example of use : -^^^^^^^^^^^^^^^^ - -| Creating a GeoConcept export file : - -:: - - ogr2ogr -f "Geoconcept" -a_srs "+init=IGNF:LAMB93" -dsco EXTENSION=txt -dsco CONFIG=tile_schema.gct tile.gxt tile.shp -lco FEATURETYPE=TILE.TILE - -| Appending new features to an existing GeoConcept export file : - -:: - - ogr2ogr -f "Geoconcept" -update -append tile.gxt tile.shp -nln TILE.TILE - -| Translating a GeoConcept export file layer into MapInfo file : - -:: - - ogr2ogr -f "MapInfo File" -dsco FORMAT=MIF tile.mif tile.gxt TILE.TILE - -See Also -~~~~~~~~ - -- `GeoConcept web site `__ diff --git a/doc/source/drivers/vector/index.rst b/doc/source/drivers/vector/index.rst index da2fda75878a..bcca5f705baa 100644 --- a/doc/source/drivers/vector/index.rst +++ b/doc/source/drivers/vector/index.rst @@ -42,7 +42,6 @@ Vector drivers esrijson filegdb flatgeobuf - geoconcept geojson geojsonseq georss diff --git a/ogr/ogrsf_frmts/CMakeLists.txt b/ogr/ogrsf_frmts/CMakeLists.txt index ea205c327fd5..272da24503d0 100644 --- a/ogr/ogrsf_frmts/CMakeLists.txt +++ b/ogr/ogrsf_frmts/CMakeLists.txt @@ -68,7 +68,6 @@ ogr_optional_driver(csv CSV) ogr_optional_driver(dgn DGN) ogr_optional_driver(gmt GMT) ogr_optional_driver(s57 S57) -ogr_optional_driver(geoconcept GEOCONCEPT) ogr_optional_driver(georss GEORSS) ogr_optional_driver(dxf DXF) ogr_optional_driver(pgdump PGDump) diff --git a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp index 35ada80be5aa..1573f0b32bc2 100644 --- a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp +++ b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp @@ -131,9 +131,6 @@ void OGRRegisterAllInternal() #ifdef IDB_ENABLED RegisterOGRIDB(); #endif -#ifdef GEOCONCEPT_ENABLED - RegisterOGRGeoconcept(); -#endif #ifdef GEORSS_ENABLED RegisterOGRGeoRSS(); #endif diff --git a/ogr/ogrsf_frmts/geoconcept/CMakeLists.txt b/ogr/ogrsf_frmts/geoconcept/CMakeLists.txt deleted file mode 100644 index c0d014b04624..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_gdal_driver( - TARGET ogr_Geoconcept - SOURCES geoconcept.h - ogrgeoconceptdatasource.cpp - ogrgeoconceptdriver.cpp - ogrgeoconceptlayer.cpp - geoconcept_syscoord.h - ogrgeoconceptdatasource.h - ogrgeoconceptlayer.h - geoconcept.c - geoconcept_syscoord.c - PLUGIN_CAPABLE - NO_DEPS) -gdal_standard_includes(ogr_Geoconcept) -if (MSVC) - target_compile_options(ogr_Geoconcept PRIVATE /wd4706) -endif () diff --git a/ogr/ogrsf_frmts/geoconcept/geoconcept.c b/ogr/ogrsf_frmts/geoconcept/geoconcept.c deleted file mode 100644 index f2e2f9dd3518..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/geoconcept.c +++ /dev/null @@ -1,5623 +0,0 @@ -/********************************************************************** - * - * Name: geoconcept.c - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements Physical Access class. - * Language: C - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008-2013, Even Rouault - * - * SPDX-License-Identifier: MIT - **********************************************************************/ - -#include "cpl_port.h" -#include -#include "geoconcept.h" -#include "cpl_conv.h" -#include "cpl_string.h" -#include "ogr_core.h" - -#define kItemSize_GCIO 256 -#define kExtraSize_GCIO 4096 -#define kIdSize_GCIO 12 -#define UNDEFINEDID_GCIO 199901L - -static const char *const gkGCCharset[] = { - /* 0 */ "", - /* 1 */ "ANSI", - /* 2 */ "DOS", - /* 3 */ "MAC"}; - -static const char *const gkGCAccess[] = { - /* 0 */ "", - /* 1 */ "NO", - /* 2 */ "READ", - /* 3 */ "UPDATE", - /* 4 */ "WRITE"}; - -static const char *const gkGCStatus[] = { - /* 0 */ "NONE", - /* 1 */ "MEMO", - /* 2 */ "EOF"}; - -static const char *const gk3D[] = { - /* 0 */ "", - /* 1 */ "2D", - /* 2 */ "3DM", - /* 3 */ "3D"}; - -static const char *const gkGCTypeKind[] = { - /* 0 */ "", - /* 1 */ "POINT", - /* 2 */ "LINE", - /* 3 */ "TEXT", - /* 4 */ "POLYGON", - /* 5 */ "MEMO", - /* 6 */ "INT", - /* 7 */ "REAL", - /* 8 */ "LENGTH", - /* 9 */ "AREA", - /*10 */ "POSITION", - /*11 */ "DATE", - /*12 */ "TIME", - /*13 */ "CHOICE", - /*14 */ "MEMO"}; - -/* -------------------------------------------------------------------- */ -/* GCIO API Prototypes */ -/* -------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------- */ -static char GCIOAPI_CALL1(*) _getHeaderValue_GCIO(const char *s) -{ - char *b, *e; - - if ((b = strchr(s, '=')) == NULL) - return NULL; - b++; - while (isspace((unsigned char)*b)) - b++; - e = b; - while (*e != '\0' && !isspace((unsigned char)*e)) - e++; - *e = '\0'; - return b; -} /* _getHeaderValue_GCIO */ - -/* -------------------------------------------------------------------- */ -const char GCIOAPI_CALL1(*) GCCharset2str_GCIO(GCCharset cs) -{ - switch (cs) - { - case vANSI_GCIO: - case vDOS_GCIO: - case vMAC_GCIO: - return gkGCCharset[cs]; - default: - return gkGCCharset[vUnknownCharset_GCIO]; - } -} /* GCCharset2str_GCIO */ - -/* -------------------------------------------------------------------- */ -GCCharset GCIOAPI_CALL str2GCCharset_GCIO(const char *s) -{ - if (strcmp(s, gkGCCharset[vANSI_GCIO]) == 0) - return vANSI_GCIO; - if (strcmp(s, gkGCCharset[vDOS_GCIO]) == 0) - return vDOS_GCIO; - if (strcmp(s, gkGCCharset[vMAC_GCIO]) == 0) - return vMAC_GCIO; - return vUnknownCharset_GCIO; -} /* str2GCCharset_GCIO */ - -/* -------------------------------------------------------------------- */ -const char GCIOAPI_CALL1(*) GCAccessMode2str_GCIO(GCAccessMode mode) -{ - switch (mode) - { - case vNoAccess_GCIO: - case vReadAccess_GCIO: - case vUpdateAccess_GCIO: - case vWriteAccess_GCIO: - return gkGCAccess[mode]; - default: - return gkGCAccess[vUnknownAccessMode_GCIO]; - } -} /* GCAccessMode2str_GCIO */ - -/* -------------------------------------------------------------------- */ -GCAccessMode GCIOAPI_CALL str2GCAccessMode_GCIO(const char *s) -{ - if (strcmp(s, gkGCAccess[vNoAccess_GCIO]) == 0) - return vNoAccess_GCIO; - if (strcmp(s, gkGCAccess[vReadAccess_GCIO]) == 0) - return vReadAccess_GCIO; - if (strcmp(s, gkGCAccess[vUpdateAccess_GCIO]) == 0) - return vUpdateAccess_GCIO; - if (strcmp(s, gkGCAccess[vWriteAccess_GCIO]) == 0) - return vWriteAccess_GCIO; - return vUnknownAccessMode_GCIO; -} /* str2GCAccessMode_GCIO */ - -/* -------------------------------------------------------------------- */ -const char GCIOAPI_CALL1(*) GCAccessStatus2str_GCIO(GCAccessStatus stts) -{ - switch (stts) - { - case vMemoStatus_GCIO: - case vEof_GCIO: - return gkGCStatus[stts]; - default: - return gkGCStatus[vNoStatus_GCIO]; - } -} /* GCAccessStatus2str_GCIO */ - -/* -------------------------------------------------------------------- */ -GCAccessStatus GCIOAPI_CALL str2GCAccessStatus_GCIO(const char *s) -{ - if (strcmp(s, gkGCStatus[vMemoStatus_GCIO]) == 0) - return vMemoStatus_GCIO; - if (strcmp(s, gkGCStatus[vEof_GCIO]) == 0) - return vEof_GCIO; - return vNoStatus_GCIO; -} /* str2GCAccessStatus_GCIO */ - -/* -------------------------------------------------------------------- */ -const char GCIOAPI_CALL1(*) GCDim2str_GCIO(GCDim sys) -{ - switch (sys) - { - case v2D_GCIO: - case v3D_GCIO: - case v3DM_GCIO: - return gk3D[sys]; - default: - return gk3D[vUnknown3D_GCIO]; - } -} /* GCDim2str_GCIO */ - -/* -------------------------------------------------------------------- */ -GCDim GCIOAPI_CALL str2GCDim(const char *s) -{ - if (strcmp(s, gk3D[v2D_GCIO]) == 0) - return v2D_GCIO; - if (strcmp(s, gk3D[v3D_GCIO]) == 0) - return v3D_GCIO; - if (strcmp(s, gk3D[v3DM_GCIO]) == 0) - return v3DM_GCIO; - return vUnknown3D_GCIO; -} /* str2GCDim */ - -/* -------------------------------------------------------------------- */ -const char GCIOAPI_CALL1(*) GCTypeKind2str_GCIO(GCTypeKind item) -{ - switch (item) - { - case vPoint_GCIO: - case vLine_GCIO: - case vText_GCIO: - case vPoly_GCIO: - case vMemoFld_GCIO: - case vIntFld_GCIO: - case vRealFld_GCIO: - case vLengthFld_GCIO: - case vAreaFld_GCIO: - case vPositionFld_GCIO: - case vDateFld_GCIO: - case vTimeFld_GCIO: - case vChoiceFld_GCIO: - case vInterFld_GCIO: - return gkGCTypeKind[item]; - default: - return gkGCTypeKind[vUnknownItemType_GCIO]; - } -} /* GCTypeKind2str_GCIO */ - -/* -------------------------------------------------------------------- */ -GCTypeKind GCIOAPI_CALL str2GCTypeKind_GCIO(const char *s) -{ - if (strcmp(s, gkGCTypeKind[vPoint_GCIO]) == 0) - return vPoint_GCIO; - if (strcmp(s, gkGCTypeKind[vLine_GCIO]) == 0) - return vLine_GCIO; - if (strcmp(s, gkGCTypeKind[vText_GCIO]) == 0) - return vText_GCIO; - if (strcmp(s, gkGCTypeKind[vPoly_GCIO]) == 0) - return vPoly_GCIO; - if (strcmp(s, gkGCTypeKind[vMemoFld_GCIO]) == 0) - return vMemoFld_GCIO; - if (strcmp(s, gkGCTypeKind[vIntFld_GCIO]) == 0) - return vIntFld_GCIO; - if (strcmp(s, gkGCTypeKind[vRealFld_GCIO]) == 0) - return vRealFld_GCIO; - if (strcmp(s, gkGCTypeKind[vLengthFld_GCIO]) == 0) - return vLengthFld_GCIO; - if (strcmp(s, gkGCTypeKind[vAreaFld_GCIO]) == 0) - return vAreaFld_GCIO; - if (strcmp(s, gkGCTypeKind[vPositionFld_GCIO]) == 0) - return vPositionFld_GCIO; - if (strcmp(s, gkGCTypeKind[vDateFld_GCIO]) == 0) - return vDateFld_GCIO; - if (strcmp(s, gkGCTypeKind[vTimeFld_GCIO]) == 0) - return vTimeFld_GCIO; - if (strcmp(s, gkGCTypeKind[vChoiceFld_GCIO]) == 0) - return vChoiceFld_GCIO; - if (strcmp(s, gkGCTypeKind[vInterFld_GCIO]) == 0) - return vInterFld_GCIO; - return vUnknownItemType_GCIO; -} /* str2GCTypeKind_GCIO */ - -/* -------------------------------------------------------------------- */ -static const char GCIOAPI_CALL1(*) _metaDelimiter2str_GCIO(char delim) -{ - switch (delim) - { - case '\t': - return "tab"; - default: - return "\t"; - } -} /* _metaDelimiter2str_GCIO */ - -/* -------------------------------------------------------------------- */ -static long GCIOAPI_CALL _read_GCIO(GCExportFileH *hGXT) -{ - VSILFILE *h; - long nread; - unsigned char c; - char *result; - - h = GetGCHandle_GCIO(hGXT); - nread = 0L; - result = GetGCCache_GCIO(hGXT); - SetGCCurrentOffset_GCIO( - hGXT, VSIFTellL(h)); /* keep offset of beginning of lines */ - while (VSIFReadL(&c, 1, 1, h) == 1) - { - if (c == '\r') /* PC '\r\n' line, MAC '\r' */ - { - if (VSIFReadL(&c, 1, 1, h) != 1) - { - c = '\n'; - } - else if (c != '\n') - { - VSIFSeekL(h, VSIFTellL(h) - 1, SEEK_SET); - c = '\n'; - } - } - - switch (c) - { - case 0X1A: - continue; /* PC end-of-file */ - case '\n': - SetGCCurrentLinenum_GCIO(hGXT, - GetGCCurrentLinenum_GCIO(hGXT) + 1L); - if (nread == 0L) - continue; - *result = '\0'; - return nread; - default: - *result = (char)c; - result++; - nread++; - if (nread == kCacheSize_GCIO) - { - CPLError(CE_Failure, CPLE_OutOfMemory, - "Too many characters at line %lu.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - return EOF; - } - } /* switch */ - } /* while */ - *result = '\0'; - - SetGCStatus_GCIO(hGXT, vEof_GCIO); - if (nread == 0L) - { - return EOF; - } - return nread; - -} /* _read_GCIO */ - -/* -------------------------------------------------------------------- */ -static vsi_l_offset GCIOAPI_CALL _get_GCIO(GCExportFileH *hGXT) -{ - if (GetGCStatus_GCIO(hGXT) == vEof_GCIO) - { - SetGCCache_GCIO(hGXT, ""); - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vUnknownIO_ItemType_GCIO); - return EOF; - } - if (GetGCStatus_GCIO(hGXT) == vMemoStatus_GCIO) - { - SetGCStatus_GCIO(hGXT, vNoStatus_GCIO); - return GetGCCurrentOffset_GCIO(hGXT); - } - if (_read_GCIO(hGXT) == EOF) - { - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vUnknownIO_ItemType_GCIO); - return (vsi_l_offset)EOF; - } - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vStdCol_GCIO); - if (strstr(GetGCCache_GCIO(hGXT), kCom_GCIO) == GetGCCache_GCIO(hGXT)) - { /* // */ - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vComType_GCIO); - if (strstr(GetGCCache_GCIO(hGXT), kHeader_GCIO) == - GetGCCache_GCIO(hGXT)) - { /* //# */ - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vHeader_GCIO); - } - else - { - if (strstr(GetGCCache_GCIO(hGXT), kPragma_GCIO) == - GetGCCache_GCIO(hGXT)) - { /* //$ */ - SetGCWhatIs_GCIO(hGXT, (GCTypeKind)vPragma_GCIO); - } - } - } - return GetGCCurrentOffset_GCIO(hGXT); -} /* _get_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _InitExtent_GCIO(GCExtent *theExtent) -{ - theExtent->XUL = HUGE_VAL; - theExtent->YUL = -HUGE_VAL; - theExtent->XLR = -HUGE_VAL; - theExtent->YLR = HUGE_VAL; -} /* _InitExtent_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExtent GCIOAPI_CALL1(*) - CreateExtent_GCIO(double Xmin, double Ymin, double Xmax, double Ymax) -{ - GCExtent *theExtent; - - if (!(theExtent = VSI_MALLOC_VERBOSE(sizeof(GCExtent)))) - { - return NULL; - } - _InitExtent_GCIO(theExtent); - theExtent->XUL = Xmin; - theExtent->YUL = Ymax; - theExtent->XLR = Xmax; - theExtent->YLR = Ymin; - - return theExtent; -} /* CreateExtent_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInitExtent_GCIO(GCExtent *theExtent) -{ - _InitExtent_GCIO(theExtent); -} /* _ReInitExtent_GCIO */ - -/* -------------------------------------------------------------------- */ -void GCIOAPI_CALL DestroyExtent_GCIO(GCExtent **theExtent) -{ - _ReInitExtent_GCIO(*theExtent); - CPLFree(*theExtent); - *theExtent = NULL; -} /* DestroyExtent_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _InitField_GCIO(GCField *theField) -{ - SetFieldName_GCIO(theField, NULL); - SetFieldID_GCIO(theField, UNDEFINEDID_GCIO); - SetFieldKind_GCIO(theField, vUnknownItemType_GCIO); - SetFieldExtra_GCIO(theField, NULL); - SetFieldList_GCIO(theField, NULL); -} /* _InitField_GCIO */ - -/* -------------------------------------------------------------------- */ -static const char GCIOAPI_CALL1(*) _NormalizeFieldName_GCIO(const char *name) -{ - if (name[0] == '@') - { - if (EQUAL(name, "@Identificateur") || EQUAL(name, kIdentifier_GCIO)) - { - return kIdentifier_GCIO; - } - else if (EQUAL(name, "@Type") || EQUAL(name, kClass_GCIO)) - { - return kClass_GCIO; - } - else if (EQUAL(name, "@Sous-type") || EQUAL(name, kSubclass_GCIO)) - { - return kSubclass_GCIO; - } - else if (EQUAL(name, "@Nom") || EQUAL(name, kName_GCIO)) - { - return kName_GCIO; - } - else if (EQUAL(name, kNbFields_GCIO)) - { - return kNbFields_GCIO; - } - else if (EQUAL(name, kX_GCIO)) - { - return kX_GCIO; - } - else if (EQUAL(name, kY_GCIO)) - { - return kY_GCIO; - } - else if (EQUAL(name, "@X'") || EQUAL(name, kXP_GCIO)) - { - return kXP_GCIO; - } - else if (EQUAL(name, "@Y'") || EQUAL(name, kYP_GCIO)) - { - return kYP_GCIO; - } - else if (EQUAL(name, kGraphics_GCIO)) - { - return kGraphics_GCIO; - } - else if (EQUAL(name, kAngle_GCIO)) - { - return kAngle_GCIO; - } - else - { - return name; - } - } - else - { - return name; - } -} /* _NormalizeFieldName_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCField GCIOAPI_CALL1(*) - _CreateField_GCIO(const char *name, long id, GCTypeKind knd, - const char *extra, const char *enums) -{ - GCField *theField; - - if (!(theField = VSI_MALLOC_VERBOSE(sizeof(GCField)))) - { - return NULL; - } - _InitField_GCIO(theField); - SetFieldName_GCIO(theField, CPLStrdup(name)); - SetFieldID_GCIO(theField, id); - SetFieldKind_GCIO(theField, knd); - if (extra && extra[0] != '\0') - SetFieldExtra_GCIO(theField, CPLStrdup(extra)); - if (enums && enums[0] != '\0') - SetFieldList_GCIO(theField, CSLTokenizeString2(enums, ";", 0)); - - return theField; -} /* _CreateField_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInitField_GCIO(GCField *theField) -{ - if (GetFieldName_GCIO(theField)) - { - CPLFree(GetFieldName_GCIO(theField)); - } - if (GetFieldExtra_GCIO(theField)) - { - CPLFree(GetFieldExtra_GCIO(theField)); - } - if (GetFieldList_GCIO(theField)) - { - CSLDestroy(GetFieldList_GCIO(theField)); - } - _InitField_GCIO(theField); -} /* _ReInitField_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _DestroyField_GCIO(GCField **theField) -{ - _ReInitField_GCIO(*theField); - CPLFree(*theField); - *theField = NULL; -} /* _DestroyField_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _findFieldByName_GCIO(CPLList *fields, const char *name) -{ - GCField *theField; - - if (fields) - { - int i = 0; - CPLList *psIter = fields; - for (; psIter; psIter = psIter->psNext, i++) - { - theField = (GCField *)psIter->pData; - if (EQUAL(GetFieldName_GCIO(theField), name)) - { - return i; - } - } - } - return -1; -} /* _findFieldByName_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCField GCIOAPI_CALL1(*) _getField_GCIO(CPLList *fields, int where) -{ - CPLList *e; - - if ((e = CPLListGet(fields, where))) - return (GCField *)CPLListGetData(e); - return NULL; -} /* _getField_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _InitSubType_GCIO(GCSubType *theSubType) -{ - SetSubTypeGCHandle_GCIO(theSubType, NULL); - SetSubTypeType_GCIO(theSubType, NULL); - SetSubTypeName_GCIO(theSubType, NULL); - SetSubTypeFields_GCIO(theSubType, NULL); /* GCField */ - SetSubTypeFeatureDefn_GCIO(theSubType, NULL); - SetSubTypeKind_GCIO(theSubType, vUnknownItemType_GCIO); - SetSubTypeID_GCIO(theSubType, UNDEFINEDID_GCIO); - SetSubTypeDim_GCIO(theSubType, v2D_GCIO); - SetSubTypeNbFields_GCIO(theSubType, -1); - SetSubTypeNbFeatures_GCIO(theSubType, 0L); - SetSubTypeBOF_GCIO(theSubType, (vsi_l_offset)EOF); - SetSubTypeBOFLinenum_GCIO(theSubType, 0L); - SetSubTypeExtent_GCIO(theSubType, NULL); - SetSubTypeHeaderWritten_GCIO(theSubType, FALSE); -} /* _InitSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCSubType GCIOAPI_CALL1(*) - _CreateSubType_GCIO(const char *subtypName, long id, GCTypeKind knd, - GCDim sys) -{ - GCSubType *theSubType; - - if (!(theSubType = VSI_MALLOC_VERBOSE(sizeof(GCSubType)))) - { - return NULL; - } - _InitSubType_GCIO(theSubType); - SetSubTypeName_GCIO(theSubType, CPLStrdup(subtypName)); - SetSubTypeID_GCIO(theSubType, id); - SetSubTypeKind_GCIO(theSubType, knd); - SetSubTypeDim_GCIO(theSubType, sys); - - return theSubType; -} /* _CreateSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInitSubType_GCIO(GCSubType *theSubType) -{ - if (GetSubTypeFeatureDefn_GCIO(theSubType)) - { - OGR_FD_Release(GetSubTypeFeatureDefn_GCIO(theSubType)); - } - if (GetSubTypeFields_GCIO(theSubType)) - { - CPLList *e; - GCField *theField; - int i, n; - if ((n = CPLListCount(GetSubTypeFields_GCIO(theSubType))) > 0) - { - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetSubTypeFields_GCIO(theSubType), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - _DestroyField_GCIO(&theField); - } - } - } - } - CPLListDestroy(GetSubTypeFields_GCIO(theSubType)); - } - if (GetSubTypeName_GCIO(theSubType)) - { - CPLFree(GetSubTypeName_GCIO(theSubType)); - } - if (GetSubTypeExtent_GCIO(theSubType)) - { - DestroyExtent_GCIO(&(GetSubTypeExtent_GCIO(theSubType))); - } - _InitSubType_GCIO(theSubType); -} /* _ReInitSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _DestroySubType_GCIO(GCSubType **theSubType) -{ - _ReInitSubType_GCIO(*theSubType); - CPLFree(*theSubType); - *theSubType = NULL; -} /* _DestroySubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _findSubTypeByName_GCIO(GCType *theClass, - const char *subtypName) -{ - GCSubType *theSubType; - - if (theClass != NULL && GetTypeSubtypes_GCIO(theClass)) - { - CPLList *e; - int n, i; - if ((n = CPLListCount(GetTypeSubtypes_GCIO(theClass))) > 0) - { - if (*subtypName == '*') - return 0; - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetTypeSubtypes_GCIO(theClass), i))) - { - if ((theSubType = (GCSubType *)CPLListGetData(e))) - { - if (EQUAL(GetSubTypeName_GCIO(theSubType), subtypName)) - { - return i; - } - } - } - } - } - } - return -1; -} /* _findSubTypeByName_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCSubType GCIOAPI_CALL1(*) _getSubType_GCIO(GCType *theClass, int where) -{ - CPLList *e; - - if ((e = CPLListGet(GetTypeSubtypes_GCIO(theClass), where))) - return (GCSubType *)CPLListGetData(e); - return NULL; -} /* _getSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _InitType_GCIO(GCType *theClass) -{ - SetTypeName_GCIO(theClass, NULL); - SetTypeSubtypes_GCIO(theClass, NULL); /* GCSubType */ - SetTypeFields_GCIO(theClass, NULL); /* GCField */ - SetTypeID_GCIO(theClass, UNDEFINEDID_GCIO); -} /* _InitType_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCType GCIOAPI_CALL1(*) _CreateType_GCIO(const char *typName, long id) -{ - GCType *theClass; - - if (!(theClass = VSI_MALLOC_VERBOSE(sizeof(GCType)))) - { - return NULL; - } - _InitType_GCIO(theClass); - SetTypeName_GCIO(theClass, CPLStrdup(typName)); - SetTypeID_GCIO(theClass, id); - - return theClass; -} /* _CreateType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInitType_GCIO(GCType *theClass) -{ - if (GetTypeSubtypes_GCIO(theClass)) - { - CPLList *e; - GCSubType *theSubType; - int i, n; - if ((n = CPLListCount(GetTypeSubtypes_GCIO(theClass))) > 0) - { - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetTypeSubtypes_GCIO(theClass), i))) - { - if ((theSubType = (GCSubType *)CPLListGetData(e))) - { - _DestroySubType_GCIO(&theSubType); - } - } - } - } - CPLListDestroy(GetTypeSubtypes_GCIO(theClass)); - } - if (GetTypeFields_GCIO(theClass)) - { - CPLList *e; - GCField *theField; - int i, n; - if ((n = CPLListCount(GetTypeFields_GCIO(theClass))) > 0) - { - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetTypeFields_GCIO(theClass), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - _DestroyField_GCIO(&theField); - } - } - } - } - CPLListDestroy(GetTypeFields_GCIO(theClass)); - } - if (GetTypeName_GCIO(theClass)) - { - CPLFree(GetTypeName_GCIO(theClass)); - } - _InitType_GCIO(theClass); -} /* _ReInitType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _DestroyType_GCIO(GCType **theClass) -{ - _ReInitType_GCIO(*theClass); - CPLFree(*theClass); - *theClass = NULL; -} /* _DestroyType_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _findTypeByName_GCIO(GCExportFileH *hGXT, - const char *typName) -{ - GCType *theClass; - GCExportFileMetadata *header; - - header = GetGCMeta_GCIO(hGXT); - if (GetMetaTypes_GCIO(header)) - { - CPLList *e; - int n, i; - if ((n = CPLListCount(GetMetaTypes_GCIO(header))) > 0) - { - if (*typName == '*') - return 0; - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetMetaTypes_GCIO(header), i))) - { - if ((theClass = (GCType *)CPLListGetData(e))) - { - if (EQUAL(GetTypeName_GCIO(theClass), typName)) - { - return i; - } - } - } - } - } - } - return -1; -} /* _findTypeByName_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCType GCIOAPI_CALL1(*) _getType_GCIO(GCExportFileH *hGXT, int where) -{ - CPLList *e; - - if ((e = CPLListGet(GetMetaTypes_GCIO(GetGCMeta_GCIO(hGXT)), where))) - return (GCType *)CPLListGetData(e); - return NULL; -} /* _getType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _InitHeader_GCIO(GCExportFileMetadata *header) -{ - SetMetaVersion_GCIO(header, NULL); - SetMetaDelimiter_GCIO(header, kTAB_GCIO[0]); - SetMetaQuotedText_GCIO(header, FALSE); - SetMetaCharset_GCIO(header, vANSI_GCIO); - SetMetaUnit_GCIO(header, "m"); - SetMetaFormat_GCIO(header, 2); - SetMetaSysCoord_GCIO(header, NULL); /* GCSysCoord */ - SetMetaPlanarFormat_GCIO(header, 0); - SetMetaHeightFormat_GCIO(header, 0); - SetMetaSRS_GCIO(header, NULL); - SetMetaTypes_GCIO(header, NULL); /* GCType */ - SetMetaFields_GCIO(header, NULL); /* GCField */ - SetMetaResolution_GCIO(header, 0.1); - SetMetaExtent_GCIO(header, NULL); -} /* _InitHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileMetadata GCIOAPI_CALL1(*) CreateHeader_GCIO(void) -{ - GCExportFileMetadata *m; - - if (!(m = VSI_MALLOC_VERBOSE(sizeof(GCExportFileMetadata)))) - { - return NULL; - } - _InitHeader_GCIO(m); - - return m; -} /* CreateHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInitHeader_GCIO(GCExportFileMetadata *header) -{ - if (GetMetaVersion_GCIO(header)) - { - CPLFree(GetMetaVersion_GCIO(header)); - } - if (GetMetaExtent_GCIO(header)) - { - DestroyExtent_GCIO(&(GetMetaExtent_GCIO(header))); - } - if (GetMetaTypes_GCIO(header)) - { - CPLList *e; - GCType *theClass; - int i, n; - if ((n = CPLListCount(GetMetaTypes_GCIO(header))) > 0) - { - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetMetaTypes_GCIO(header), i))) - { - if ((theClass = (GCType *)CPLListGetData(e))) - { - _DestroyType_GCIO(&theClass); - } - } - } - } - CPLListDestroy(GetMetaTypes_GCIO(header)); - } - if (GetMetaFields_GCIO(header)) - { - CPLList *e; - GCField *theField; - int i, n; - if ((n = CPLListCount(GetMetaFields_GCIO(header))) > 0) - { - for (i = 0; i < n; i++) - { - if ((e = CPLListGet(GetMetaFields_GCIO(header), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - _DestroyField_GCIO(&theField); - } - } - } - } - CPLListDestroy(GetMetaFields_GCIO(header)); - } - if (GetMetaSRS_GCIO(header)) - { - OSRRelease(GetMetaSRS_GCIO(header)); - } - if (GetMetaSysCoord_GCIO(header)) - { - DestroySysCoord_GCSRS(&(GetMetaSysCoord_GCIO(header))); - } - - _InitHeader_GCIO(header); -} /* _ReInitHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -void GCIOAPI_CALL DestroyHeader_GCIO(GCExportFileMetadata **m) -{ - _ReInitHeader_GCIO(*m); - CPLFree(*m); - *m = NULL; -} /* DestroyHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _Init_GCIO(GCExportFileH *H) -{ - SetGCCache_GCIO(H, ""); - SetGCPath_GCIO(H, NULL); - SetGCBasename_GCIO(H, NULL); - SetGCExtension_GCIO(H, NULL); - SetGCHandle_GCIO(H, NULL); - SetGCCurrentOffset_GCIO(H, 0L); - SetGCCurrentLinenum_GCIO(H, 0L); - SetGCNbObjects_GCIO(H, 0L); - SetGCMeta_GCIO(H, NULL); - SetGCMode_GCIO(H, vNoAccess_GCIO); - SetGCStatus_GCIO(H, vNoStatus_GCIO); - SetGCWhatIs_GCIO(H, (GCTypeKind)vUnknownIO_ItemType_GCIO); -} /* _Init_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCExportFileH GCIOAPI_CALL1(*) - _Create_GCIO(const char *pszGeoconceptFile, const char *ext, - const char *mode) -{ - GCExportFileH *hGXT; - - CPLDebug("GEOCONCEPT", "allocating %d bytes for GCExportFileH", - (int)sizeof(GCExportFileH)); - if (!(hGXT = VSI_MALLOC_VERBOSE(sizeof(GCExportFileH)))) - { - return NULL; - } - - _Init_GCIO(hGXT); - SetGCPath_GCIO(hGXT, CPLStrdup(CPLGetDirname(pszGeoconceptFile))); - SetGCBasename_GCIO(hGXT, CPLStrdup(CPLGetBasename(pszGeoconceptFile))); - SetGCExtension_GCIO(hGXT, CPLStrdup(ext ? ext : "gxt")); - SetGCMode_GCIO( - hGXT, (mode[0] == 'w' - ? vWriteAccess_GCIO - : (mode[0] == 'a' ? vUpdateAccess_GCIO : vReadAccess_GCIO))); - - return hGXT; -} /* _Create_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _ReInit_GCIO(GCExportFileH *hGXT) -{ - if (GetGCMeta_GCIO(hGXT)) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - } - if (GetGCHandle_GCIO(hGXT)) - { - VSIFCloseL(GetGCHandle_GCIO(hGXT)); - } - if (GetGCExtension_GCIO(hGXT)) - { - CPLFree(GetGCExtension_GCIO(hGXT)); - } - if (GetGCBasename_GCIO(hGXT)) - { - CPLFree(GetGCBasename_GCIO(hGXT)); - } - if (GetGCPath_GCIO(hGXT)) - { - CPLFree(GetGCPath_GCIO(hGXT)); - } - SetGCCache_GCIO(hGXT, ""); - _Init_GCIO(hGXT); -} /* _ReInit_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _Destroy_GCIO(GCExportFileH **hGXT, int delFile) -{ - if (delFile && GetGCMode_GCIO(*hGXT) == vWriteAccess_GCIO) - { - VSIFCloseL(GetGCHandle_GCIO(*hGXT)); - SetGCHandle_GCIO(*hGXT, NULL); - char *pszTmp = CPLStrdup(CPLFormFilename(GetGCPath_GCIO(*hGXT), - GetGCBasename_GCIO(*hGXT), - GetGCExtension_GCIO(*hGXT))); - VSIUnlink(pszTmp); - VSIFree(pszTmp); - } - _ReInit_GCIO(*hGXT); - CPLFree(*hGXT); - *hGXT = NULL; -} /* _Destroy_GCIO */ - -/* -------------------------------------------------------------------- */ -static int _checkSchema_GCIO(GCExportFileH *hGXT) -{ - GCExportFileMetadata *Meta; - int nT, iT, nS, iS, nF, iF, nU, iId, iCl, iSu, iNa, iNb, iX, iY, iXP, iYP, - iGr, iAn; - GCField *theField; - GCSubType *theSubType; - GCType *theClass; - CPLList *e; - - if (!(Meta = GetGCMeta_GCIO(hGXT))) - { - return TRUE; /* FIXME */ - } - if ((nT = CPLListCount(GetMetaTypes_GCIO(Meta))) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept schema without types!\n"); - return FALSE; - } - for (iT = 0; iT < nT; iT++) - { - if ((e = CPLListGet(GetMetaTypes_GCIO(Meta), iT))) - { - if ((theClass = (GCType *)CPLListGetData(e))) - { - if ((nS = CPLListCount(GetTypeSubtypes_GCIO(theClass))) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept type %s without sub-types!\n", - GetTypeName_GCIO(theClass)); - return FALSE; - } - for (iS = 0; iS < nS; iS++) - { - if ((e = CPLListGet(GetTypeSubtypes_GCIO(theClass), iS))) - { - if ((theSubType = (GCSubType *)CPLListGetData(e))) - { - if ((nF = CPLListCount( - GetSubTypeFields_GCIO(theSubType))) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept sub-type %s.%s without " - "fields!\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - nU = 0; - iId = iCl = iSu = iNa = iNb = iX = iY = iXP = iYP = - iGr = iAn = -1; - for (iF = 0; iF < nF; iF++) - { - if ((e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), - iF))) - { - if ((theField = - (GCField *)CPLListGetData(e))) - { - if (IsPrivateField_GCIO(theField)) - { - if (EQUAL( - GetFieldName_GCIO(theField), - kIdentifier_GCIO)) - iId = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kClass_GCIO)) - iCl = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kSubclass_GCIO)) - iSu = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kName_GCIO)) - iNa = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kNbFields_GCIO)) - iNb = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kX_GCIO)) - iX = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kY_GCIO)) - iY = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kXP_GCIO)) - iXP = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kYP_GCIO)) - iYP = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kGraphics_GCIO)) - iGr = iF; - else if (EQUAL(GetFieldName_GCIO( - theField), - kAngle_GCIO)) - iAn = iF; - } - else - { - nU++; - } - } - } - } - if (iId == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kIdentifier_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - else if (iId != 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s must " - "be the first field of %s.%s!\n", - kIdentifier_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iCl == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kClass_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - else if (iCl - iId != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s must " - "be the second field of %s.%s!\n", - kClass_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iSu == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kSubclass_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - else if (iSu - iCl != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s must " - "be the third field of %s.%s!\n", - kSubclass_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iNa == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kName_GCIO, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - else if (iNa - iSu != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s must " - "be the forth field of %s.%s!\n", - kName_GCIO, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iNb == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kNbFields_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iX == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kX_GCIO, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iY == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kY_GCIO, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iY - iX != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept geometry fields %s, %s " - "must be consecutive for %s.%s!\n", - kX_GCIO, kY_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (GetSubTypeKind_GCIO(theSubType) == vLine_GCIO) - { - if (iXP == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kXP_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iYP == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kYP_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iYP - iXP != 1) - { - CPLError( - CE_Failure, CPLE_AppDefined, - "Geoconcept geometry fields %s, %s " - "must be consecutive for %s.%s!\n", - kXP_GCIO, kYP_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - if (iXP - iY != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept geometry fields %s, " - "%s, %s, %s must be consecutive " - "for %s.%s!\n", - kX_GCIO, kY_GCIO, kXP_GCIO, - kYP_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - } - else - { - if (iXP != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept sub-type %s.%s has a " - "mandatory field %s only required " - "on linear type!\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), - kXP_GCIO); - return FALSE; - } - if (iYP != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept sub-type %s.%s has a " - "mandatory field %s only required " - "on linear type!\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), - kYP_GCIO); - return FALSE; - } - } - if (GetSubTypeKind_GCIO(theSubType) == vLine_GCIO || - GetSubTypeKind_GCIO(theSubType) == vPoly_GCIO) - { - if (iGr == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept mandatory field %s is " - "missing on %s.%s!\n", - kGraphics_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - else - { - if (!(((iGr != -1) && ((iGr == iY + 1) || - (iGr == iYP + 1))) || - (iGr == -1))) - - { - CPLError( - CE_Failure, CPLE_AppDefined, - "Geoconcept geometry fields %s, %s " - "must be consecutive for %s.%s!\n", - iYP != -1 ? kYP_GCIO : kY_GCIO, - kGraphics_GCIO, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - return FALSE; - } - } - if (iAn != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept sub-type %s.%s has a " - "field %s only required on " - "ponctual or text type!\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), - kAngle_GCIO); - return FALSE; - } - } - else - { - if (iGr != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept sub-type %s.%s has a " - "mandatory field %s only required " - "on linear or polygonal type!\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), - kGraphics_GCIO); - return FALSE; - } - } - SetSubTypeNbFields_GCIO(theSubType, nU); - SetSubTypeGCHandle_GCIO(theSubType, hGXT); - } - } - } - } - } - } - - return TRUE; -} /* _checkSchema_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCExportFileMetadata GCIOAPI_CALL1(*) - _parsePragma_GCIO(GCExportFileH *hGXT) -{ - GCExportFileMetadata *Meta; - char *p, *e; - - Meta = GetGCMeta_GCIO(hGXT); - - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataVERSION_GCIO)) != NULL) - { - if (GetMetaVersion_GCIO(Meta)) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - - /* //$VERSION char* */ - p += strlen(kMetadataVERSION_GCIO); - while (isspace((unsigned char)*p)) - p++; - e = p; - while (isalpha((unsigned char)*p)) - p++; - *p = '\0'; - SetMetaVersion_GCIO(Meta, CPLStrdup(e)); - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataDELIMITER_GCIO)) != NULL) - { - /* //$DELIMITER "char*" */ - if ((p = strchr(p, '"'))) - { - p++; - e = p; - while (*p != '"' && *p != '\0') - p++; - *p = '\0'; - if (!(EQUAL(e, "tab") || EQUAL(e, kTAB_GCIO))) - { - CPLDebug("GEOCONCEPT", "%s%s only supports \"tab\" value", - kPragma_GCIO, kMetadataDELIMITER_GCIO); - SetMetaDelimiter_GCIO(Meta, kTAB_GCIO[0]); - } - else - { - SetMetaDelimiter_GCIO(Meta, kTAB_GCIO[0]); - } - } - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataQUOTEDTEXT_GCIO)) != NULL) - { - /* //$QUOTED-TEXT "char*" */ - if ((p = strchr(p, '"'))) - { - p++; - e = p; - while (*p != '"' && *p != '\0') - p++; - *p = '\0'; - if (EQUAL(e, "no")) - { - SetMetaQuotedText_GCIO(Meta, FALSE); - } - else - { - SetMetaQuotedText_GCIO(Meta, TRUE); - } - } - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataCHARSET_GCIO)) != NULL) - { - /* //$CHARSET char* */ - p += strlen(kMetadataCHARSET_GCIO); - while (isspace((unsigned char)*p)) - p++; - e = p; - while (isalpha((unsigned char)*p)) - p++; - *p = '\0'; - SetMetaCharset_GCIO(Meta, str2GCCharset_GCIO(e)); - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataUNIT_GCIO)) != NULL) - { - /* //$UNIT Distance|Angle:char* */ - if ((p = strchr(p, ':'))) - { - p++; - while (isspace((unsigned char)*p)) - p++; - e = p; - while (isalpha((unsigned char)*p) || *p == '.') - p++; - *p = '\0'; - SetMetaUnit_GCIO(Meta, e); /* FIXME : check value ? */ - } - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataFORMAT_GCIO)) != NULL) - { - /* //$FORMAT 1|2 */ - p += strlen(kMetadataFORMAT_GCIO); - while (isspace((unsigned char)*p)) - p++; - e = p; - if (*e == '1') - { - SetMetaFormat_GCIO(Meta, 1); - } - else - { - SetMetaFormat_GCIO(Meta, 2); - } - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataSYSCOORD_GCIO)) != NULL) - { - int v, z; - GCSysCoord *syscoord; - - if (GetMetaSysCoord_GCIO(Meta)) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - - /* //$SYSCOORD {Type: int} [ ; { TimeZone: TimeZoneValue } ] */ - v = -1; - z = -1; - if ((p = strchr(p, ':'))) - { - p++; - while (isspace((unsigned char)*p)) - p++; - e = p; - if (*p == '-') - p++; /* allow -1 as SysCoord */ - while (isdigit((unsigned char)*p)) - p++; - *p = '\0'; - if (sscanf(e, "%d", &v) != 1) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid SRS identifier. " - "Geoconcept export syntax error at line %ld.", - GetGCCurrentLinenum_GCIO(hGXT)); - return NULL; - } - if ((p = strrchr(GetGCCache_GCIO(hGXT), ';'))) - { - if ((p = strchr(p, ':'))) - { - p++; - while (isspace((unsigned char)*p)) - p++; - e = p; - if (*p == '-') - p++; /* allow -1 as TimeZone */ - while (isdigit((unsigned char)*p)) - p++; - *p = '\0'; - if (sscanf(e, "%d", &z) != 1) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid TimeZone. " - "Geoconcept export syntax error at line %ld.", - GetGCCurrentLinenum_GCIO(hGXT)); - return NULL; - } - } - } - if (!(syscoord = CreateSysCoord_GCSRS(v, z))) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - SetMetaSysCoord_GCIO(Meta, syscoord); - } - return Meta; - } - if ((p = strstr(GetGCCache_GCIO(hGXT), kMetadataFIELDS_GCIO)) != NULL) - { - char **kv, **vl, *nm, **fl; - int whereClass, v, i, n, - mask = - CSLT_HONOURSTRINGS | CSLT_STRIPLEADSPACES | CSLT_STRIPENDSPACES; - GCType *theClass; - GCSubType *theSubType; - GCField *theField; - /* //$FIELDS +Class=char*; *Subclass=char*; *Kind=1..4; - * *Fields=(Private#)?char*(\t((Private#)?char*))* */ - p += strlen(kMetadataFIELDS_GCIO); - kv = CSLTokenizeString2(p, ";", mask); - if (!kv || CSLCount(kv) != 4) - { - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - CPLError( - CE_Failure, CPLE_AppDefined, - "Expected: //$FIELDS +Class=char*; *Subclass=char*; " - "*Kind=1..4; *Fields=(Private#)?char*(\\t((Private#)?char*))*\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - p, GetGCCurrentLinenum_GCIO(hGXT)); - return NULL; - } - for (i = 0; i < 4; i++) - CPLDebug("GEOCONCEPT", "%d kv[%d]=[%s]\n", __LINE__, i, kv[i]); - /* Class=char* */ - vl = CSLTokenizeString2(kv[0], "=", 0); - if (!vl || CSLCount(vl) != 2) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: Class=char*\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - kv[0], GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - for (i = 0; i < 2; i++) - CPLDebug("GEOCONCEPT", "%d vl[%d]=[%s]\n", __LINE__, i, vl[i]); - if (!EQUAL(vl[0], "Class")) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: 'Class'\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - vl[0], GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - p = vl[1]; - e = p; - if ((whereClass = _findTypeByName_GCIO(hGXT, e)) == -1) - { - if (!(theClass = AddType_GCIO(hGXT, e, -1))) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept export syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - } - else - { - theClass = _getType_GCIO(hGXT, whereClass); - } - CSLDestroy(vl); - /* Subclass=char* */ - vl = CSLTokenizeString2(kv[1], "=", mask); - if (!vl || CSLCount(vl) != 2) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: Subclass=char*\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - kv[1], GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - for (i = 0; i < 2; i++) - CPLDebug("GEOCONCEPT", "%d vl[%d]=[%s]\n", __LINE__, i, vl[i]); - p = vl[0]; - if (!EQUAL(p, "Subclass")) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: 'Subclass'\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - p, GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - p = vl[1]; - e = p; - if (_findSubTypeByName_GCIO(theClass, e) != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "[%s] already exists.\n" - "Geoconcept export syntax error at line %ld.\n", - e, GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - nm = CPLStrdup(e); - CSLDestroy(vl); - /* Kind=1..4 */ - vl = CSLTokenizeString2(kv[2], "=", mask); - if (!vl || CSLCount(vl) != 2) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: Kind=1..4\n" - "Found: [%s]" - "Geoconcept export syntax error at line %ld.\n", - kv[2], GetGCCurrentLinenum_GCIO(hGXT)); - CPLFree(nm); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - for (i = 0; i < 2; i++) - CPLDebug("GEOCONCEPT", "%d vl[%d]=[%s]\n", __LINE__, i, vl[i]); - p = vl[0]; - if (!EQUAL(p, "Kind")) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: 'Kind'\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - p, GetGCCurrentLinenum_GCIO(hGXT)); - CPLFree(nm); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - p = vl[1]; - e = p; - while (isdigit((unsigned char)*p)) - p++; - *p = '\0'; - if (sscanf(e, "%d", &v) != 1 || v < 1 || v > 4) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Geometry type.\n" - "Geoconcept export syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - CPLFree(nm); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - CSLDestroy(vl); - if (!(theSubType = AddSubType_GCIO(hGXT, GetTypeName_GCIO(theClass), nm, - -1, (GCTypeKind)v, vUnknown3D_GCIO))) - { - CPLFree(nm); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept export syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - return NULL; - } - CPLFree(nm); - /* Fields=(Private#)?char*(\s((Private#)?char*))* */ - vl = CSLTokenizeString2(kv[3], "=", mask); - if (!vl || CSLCount(vl) != 2) - { - CPLError( - CE_Failure, CPLE_AppDefined, - "Expected: Fields=(Private#)?char*(\\t((Private#)?char*))*\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - kv[3], GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - CSLDestroy(kv); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - for (i = 0; i < 2; i++) - CPLDebug("GEOCONCEPT", "%d vl[%d]=[%s]\n", __LINE__, i, vl[i]); - CSLDestroy(kv); - p = vl[0]; - if (!EQUAL(p, "Fields")) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: 'Fields'\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - p, GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(vl); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - fl = CSLTokenizeString2(vl[1], "\t", mask); - if (!fl || (n = CSLCount(fl)) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Expected: (Private#)?char*(\\t((Private#)?char*))*\n" - "Found: [%s]\n" - "Geoconcept export syntax error at line %ld.\n", - vl[1], GetGCCurrentLinenum_GCIO(hGXT)); - CSLDestroy(fl); - CSLDestroy(vl); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - CSLDestroy(vl); - for (i = 0; i < n; i++) - { - p = fl[i]; - CPLDebug("GEOCONCEPT", "%d fl[%d]=[%s]\n", __LINE__, i, p); - e = p; - if (EQUALN(p, kPrivate_GCIO, strlen(kPrivate_GCIO))) - { - p += strlen(kPrivate_GCIO); - e = p - 1; - *e = '@'; - } - nm = CPLStrdup(e); - CPLDebug("GEOCONCEPT", "%d e=[%s]\n", __LINE__, e); - theField = - AddSubTypeField_GCIO(hGXT, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), -1, nm, - -1, vUnknownItemType_GCIO, NULL, NULL); - if (theField == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept export syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - CPLFree(nm); - CSLDestroy(fl); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - return NULL; - } - CPLDebug("GEOCONCEPT", "%d %s.%s@%s-1 added\n", __LINE__, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), nm); - CPLFree(nm); - } - CSLDestroy(fl); - SetSubTypeHeaderWritten_GCIO(theSubType, TRUE); - return Meta; - } - /* end of definitions ... */ /* FIXME */ - if ((strstr(GetGCCache_GCIO(hGXT), k3DOBJECTMONO_GCIO)) || - (strstr(GetGCCache_GCIO(hGXT), k3DOBJECT_GCIO)) || - (strstr(GetGCCache_GCIO(hGXT), k2DOBJECT_GCIO))) - /* next reading will be in cache ! */ - SetGCStatus_GCIO(hGXT, vMemoStatus_GCIO); - /* unknown pragma ... */ - return Meta; -} /* _parsePragma_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRGeometryH GCIOAPI_CALL _buildOGRGeometry_GCIO( - GCExportFileMetadata *Meta, GCSubType *theSubType, int i, - const char **papszFields, int nbtp, GCDim d, OGREnvelope *bbox) -{ - OGRGeometryH g; - OGRwkbGeometryType gt; - double x, y, z; - int ip, np, buildGeom; - - g = NULL; - if (bbox == NULL) - { - buildGeom = TRUE; - } - else - { - buildGeom = FALSE; - } - z = 0.0; - switch (GetSubTypeKind_GCIO(theSubType)) - { - case vPoint_GCIO: - case vText_GCIO: /* FIXME : treat as point ? */ - gt = wkbPoint; - break; - case vLine_GCIO: - gt = wkbLineString; - break; - case vPoly_GCIO: - gt = wkbMultiPolygon; - break; - default: - gt = wkbUnknown; - break; - } - if (buildGeom) - { - if (!(g = OGR_G_CreateGeometry(gt))) - { - return NULL; - } - OGR_G_SetCoordinateDimension(g, - d == v3D_GCIO || d == v3DM_GCIO ? 3 : 2); - } - if (!GetMetaSRS_GCIO(Meta) && GetMetaSysCoord_GCIO(Meta)) - { - SetMetaSRS_GCIO(Meta, SysCoord2OGRSpatialReference_GCSRS( - GetMetaSysCoord_GCIO(Meta))); - } - if (buildGeom) - { - if (GetMetaSRS_GCIO(Meta)) - { - OGR_G_AssignSpatialReference(g, GetMetaSRS_GCIO(Meta)); - } - } - - /* - * General structure : - * X<>Y[<>Z]{<>More Graphics} - */ - - if (gt == wkbPoint) - { - if (i + 2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0) > nbtp) - { - OGR_G_DestroyGeometry(g); - return NULL; - } - /* - * More Graphics : - * Angle - * Angle in tenth of degrees (counterclockwise) of the symbol - * displayed to represent the ponctual entity or angle of the text - * entity NOT IMPLEMENTED - */ - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(g, x, y, z); - else - OGR_G_AddPoint_2D(g, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - return g; - } - - if (gt == wkbLineString) - { - if (i + 2 * (2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0)) + 1 > - nbtp) - { - OGR_G_DestroyGeometry(g); - return NULL; - } - - /* - * More Graphics : - * XP<>YP[<>ZP]Nr points=k[<>X<>Y[<>Z]]k... - */ - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(g, x, y, z); - else - OGR_G_AddPoint_2D(g, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - /* skip XP<>YP[<>ZP] : the last point is in k[<>X<>Y[<>Z]]k */ - i++; - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - i++; - } - np = atoi(papszFields[i]); - i++; - for (ip = 1; ip <= np; ip++) - { - if (i + 2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0) > nbtp) - { - OGR_G_DestroyGeometry(g); - return NULL; - } - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(g, x, y, z); - else - OGR_G_AddPoint_2D(g, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - } - return g; - } - - if (gt == wkbMultiPolygon) - { - /* - * More Graphics : - * {Single Polygon{<>NrPolys=j[<>X<>Y[<>Z]<>Single Polygon]j}} - * with Single Polygon : - * Nr points=k[<>X<>Y[<>Z]]k... - */ - CPLList *Lpo, *e; - OGRGeometryH outer, ring; - int npo, ipo, ilpo; - - Lpo = e = NULL; - outer = ring = NULL; - if (i + 2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0) + 1 > nbtp) - { - goto onError; - } - if (buildGeom) - { - if (!(outer = OGR_G_CreateGeometry(wkbPolygon))) - { - goto onError; - } - OGR_G_SetCoordinateDimension(outer, - OGR_G_GetCoordinateDimension(g)); - if (GetMetaSRS_GCIO(Meta)) - { - OGR_G_AssignSpatialReference(outer, GetMetaSRS_GCIO(Meta)); - } - if (!(ring = OGR_G_CreateGeometry(wkbLinearRing))) - { - OGR_G_DestroyGeometry(outer); - goto onError; - } - OGR_G_SetCoordinateDimension(ring, OGR_G_GetCoordinateDimension(g)); - if (GetMetaSRS_GCIO(Meta)) - { - OGR_G_AssignSpatialReference(ring, GetMetaSRS_GCIO(Meta)); - } - } - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(ring, x, y, z); - else - OGR_G_AddPoint_2D(ring, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - np = atoi(papszFields[i]); - i++; - if (np < 0 || - (np > 0 && - i + (GIntBig)(2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0)) * - np > - nbtp)) - { - OGR_G_DestroyGeometry(outer); - OGR_G_DestroyGeometry(ring); - goto onError; - } - for (ip = 1; ip <= np; ip++) - { - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(ring, x, y, z); - else - OGR_G_AddPoint_2D(ring, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - } - if (buildGeom) - { - OGR_G_AddGeometryDirectly(outer, ring); - if ((Lpo = CPLListAppend(Lpo, outer)) == NULL) - { - CPLError(CE_Failure, CPLE_OutOfMemory, - "failed to add a polygon to subtype '%s.%s'.\n", - GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType)), - GetSubTypeName_GCIO(theSubType)); - OGR_G_DestroyGeometry(outer); - goto onError; - } - } - /* additional ring : either holes, or islands */ - if (i < nbtp - 1) - { - npo = atoi(papszFields[i]); - i++; - for (ipo = 1; ipo <= npo; ipo++) - { - if (i + (2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0) + 1) > - nbtp) - { - goto onError; - } - if (buildGeom) - { - if (!(ring = OGR_G_CreateGeometry(wkbLinearRing))) - { - goto onError; - } - OGR_G_SetCoordinateDimension( - ring, OGR_G_GetCoordinateDimension(g)); - if (GetMetaSRS_GCIO(Meta)) - { - OGR_G_AssignSpatialReference(ring, - GetMetaSRS_GCIO(Meta)); - } - } - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(ring, x, y, z); - else - OGR_G_AddPoint_2D(ring, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - np = atoi(papszFields[i]); - i++; - for (ip = 1; ip <= np; ip++) - { - if (i + (2 + ((d == v3D_GCIO || d == v3DM_GCIO) ? 1 : 0)) > - nbtp) - { - OGR_G_DestroyGeometry(ring); - goto onError; - } - x = CPLAtof(papszFields[i]); - i++; - y = CPLAtof(papszFields[i]); - i++; - if (d == v3D_GCIO || d == v3DM_GCIO) - { - z = CPLAtof(papszFields[i]); - i++; - } - if (buildGeom) - { - if (OGR_G_GetCoordinateDimension(g) == 3) - OGR_G_AddPoint(ring, x, y, z); - else - OGR_G_AddPoint_2D(ring, x, y); - } - else - { - MergeOGREnvelope_GCIO(bbox, x, y); - } - } - if (buildGeom) - { - /* is the ring a hole or another polygon ? */ - const int nListCount = CPLListCount(Lpo); - for (ilpo = 0; ilpo < nListCount; ilpo++) - { - if ((e = CPLListGet(Lpo, ilpo))) - { - if ((outer = (OGRGeometryH)CPLListGetData(e))) - { - OGRGeometryH hPolyRing = - OGR_G_CreateGeometry(wkbPolygon); - int bRes; - if (OGR_G_AddGeometryDirectly( - hPolyRing, ring) != OGRERR_NONE) - { - OGR_G_DestroyGeometry(hPolyRing); - goto onError; - } - bRes = OGR_G_Contains(outer, hPolyRing); - OGR_G_RemoveGeometry(hPolyRing, 0, FALSE); - OGR_G_DestroyGeometry(hPolyRing); - if (bRes) - { - OGR_G_AddGeometryDirectly(outer, ring); - ring = NULL; - break; - } - } - } - } - if (ring) - { - /* new polygon */ - if (!(outer = OGR_G_CreateGeometry(wkbPolygon))) - { - OGR_G_DestroyGeometry(ring); - goto onError; - } - OGR_G_SetCoordinateDimension( - outer, OGR_G_GetCoordinateDimension(g)); - if (GetMetaSRS_GCIO(Meta)) - { - OGR_G_AssignSpatialReference(outer, - GetMetaSRS_GCIO(Meta)); - } - OGR_G_AddGeometryDirectly(outer, ring); - if ((Lpo = CPLListAppend(Lpo, outer)) == NULL) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to add a polygon to subtype '%s.%s'.\n", - GetTypeName_GCIO( - GetSubTypeType_GCIO(theSubType)), - GetSubTypeName_GCIO(theSubType)); - OGR_G_DestroyGeometry(outer); - goto onError; - } - } - } - } - } - if (Lpo) - { - if ((npo = CPLListCount(Lpo)) > 0) - { - for (ipo = 0; ipo < npo; ipo++) - { - if ((e = CPLListGet(Lpo, ipo))) - { - if ((outer = (OGRGeometryH)CPLListGetData(e))) - { - OGR_G_AddGeometryDirectly(g, outer); - } - } - } - } - CPLListDestroy(Lpo); - } - return g; - - onError: - if (Lpo) - { - if ((npo = CPLListCount(Lpo)) > 0) - { - for (ipo = 0; ipo < npo; ipo++) - { - if ((e = CPLListGet(Lpo, ipo))) - { - if ((outer = (OGRGeometryH)CPLListGetData(e))) - { - OGR_G_DestroyGeometry(outer); - } - } - } - } - CPLListDestroy(Lpo); - } - if (g) - OGR_G_DestroyGeometry(g); - } - - return NULL; -} /* _buildOGRGeometry_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRFeatureH GCIOAPI_CALL _buildOGRFeature_GCIO(GCExportFileH *H, - GCSubType **theSubType, - GCDim d, - OGREnvelope *bbox) -{ - GCExportFileMetadata *Meta; - char **papszFields, delim[2] = {0}, tdst[kItemSize_GCIO]; - int whereClass, whereSubType, i, j, nbstf, nbf, nbtf, buildFeature; - GCType *theClass; - GCField *theField; - OGRFieldDefnH fld; - OGRFeatureDefnH fd; - OGRFeatureH f; - OGRGeometryH g; - int bTokenBehavior = CSLT_ALLOWEMPTYTOKENS; - - fd = NULL; - f = NULL; - Meta = GetGCMeta_GCIO(H); - delim[0] = GetMetaDelimiter_GCIO(Meta); - delim[1] = '\0'; - if (d == vUnknown3D_GCIO) - d = v2D_GCIO; - if (bbox == NULL) - { - buildFeature = TRUE; - } - else - { - buildFeature = FALSE; - } - CPLDebug("GEOCONCEPT", "buildFeature is %s", - buildFeature ? "true" : "false"); - - /* due to the order of fields, we know how to proceed : */ - /* A.- Line syntax : */ - /* Object internal identifier */ - /* Class */ - /* Subclass */ - /* Name */ - /* NbFields */ - /* User's field [0..N] */ - /* Graphics */ - /* Graphics depends on the Kind of the */ - /* B.- Algorithm : */ - /* 1.- Get Class */ - /* 2.- Get Subclass */ - /* 3.- Find feature in schema */ - /* 4.- Get Kind */ - /* 5.- Get NbFields */ - /* 6.- Get Geometry as 5+NbFields field */ - /* 7.- Parse Geometry and build OGRGeometryH */ - /* 8.- Compute extent and update file extent */ - /* 9.- increment number of features */ - /* FIXME : add index when reading feature to */ - /* allow direct access ! */ - if (GetMetaQuotedText_GCIO(Meta)) - { - bTokenBehavior |= CSLT_HONOURSTRINGS; - } - CPLDebug("GEOCONCEPT", "Cache=[%s] delim=[%s]", GetGCCache_GCIO(H), delim); - if (!(papszFields = - CSLTokenizeString2(GetGCCache_GCIO(H), delim, bTokenBehavior))) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, Geoconcept line syntax is wrong.\n", - GetGCCurrentLinenum_GCIO(H)); - return NULL; - } - if ((nbtf = CSLCount(papszFields)) <= 5) - { - CSLDestroy(papszFields); - CPLError( - CE_Failure, CPLE_AppDefined, - "Line %ld, Missing fields (at least 5 are expected, %d found).\n", - GetGCCurrentLinenum_GCIO(H), nbtf); - return NULL; - } - /* Class */ - if ((whereClass = _findTypeByName_GCIO(H, papszFields[1])) == -1) - { - if (CPLListCount(GetMetaTypes_GCIO(Meta)) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, %s%s pragma expected from type definition " - "before objects dump.", - GetGCCurrentLinenum_GCIO(H), kPragma_GCIO, - kMetadataFIELDS_GCIO); - } - else - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, Unknown type '%s'.\n", - GetGCCurrentLinenum_GCIO(H), papszFields[1]); - } - CSLDestroy(papszFields); - return NULL; - } - theClass = _getType_GCIO(H, whereClass); - if (theClass == NULL) - { - CSLDestroy(papszFields); - return NULL; - } - if (*theSubType) - { - /* reading ... */ - if (!EQUAL(GetTypeName_GCIO(GetSubTypeType_GCIO(*theSubType)), - GetTypeName_GCIO(theClass))) - { - CSLDestroy(papszFields); - return NULL; - } - } - /* Subclass */ - if ((whereSubType = _findSubTypeByName_GCIO(theClass, papszFields[2])) == - -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, Unknown subtype found '%s' for type '%s'.\n", - GetGCCurrentLinenum_GCIO(H), papszFields[2], papszFields[1]); - CSLDestroy(papszFields); - return NULL; - } - if (*theSubType) - { - GCSubType *psSubType = _getSubType_GCIO(theClass, whereSubType); - if (psSubType == NULL || !EQUAL(GetSubTypeName_GCIO(psSubType), - GetSubTypeName_GCIO(*theSubType))) - { - CSLDestroy(papszFields); - return NULL; - } - } - else - { - *theSubType = _getSubType_GCIO(theClass, whereSubType); - CPLAssert(*theSubType != NULL); - } - snprintf(tdst, kItemSize_GCIO - 1, "%s.%s", GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(*theSubType)); - tdst[kItemSize_GCIO - 1] = '\0'; - /* Name */ - if (_findFieldByName_GCIO(GetSubTypeFields_GCIO(*theSubType), kName_GCIO) == - -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, missing mandatory field %s for type '%s'.\n", - GetGCCurrentLinenum_GCIO(H), kName_GCIO, tdst); - CSLDestroy(papszFields); - return NULL; - } - nbf = 4; - /* NbFields */ - nbstf = GetSubTypeNbFields_GCIO(*theSubType); - if (nbstf == -1) - { - /* figure out how many user's attributes we've got : */ - i = 1 + nbf; - nbstf = 0; - while ((theField = GetSubTypeField_GCIO(*theSubType, i))) - { - if (IsPrivateField_GCIO(theField)) - { - break; - }; // FIXME: could count geometry private fields ... - nbstf++; - SetSubTypeNbFields_GCIO(*theSubType, nbstf); - i++; - } - } - if (nbtf < 1 + nbf + nbstf + 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, Total number of fields differs with type " - "definition '%s' (%d found, at least %d expected).\n", - GetGCCurrentLinenum_GCIO(H), tdst, nbtf, 1 + nbf + nbstf + 1); - CSLDestroy(papszFields); - return NULL; - } - i = atoi(papszFields[nbf]); - if (i != nbstf) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Line %ld, Number of user's fields differs with type " - "definition '%s' (%d found, %d expected).\n", - GetGCCurrentLinenum_GCIO(H), tdst, i, nbstf); - CSLDestroy(papszFields); - return NULL; - } - /* - * the Subclass has no definition : let's build one - */ - if (!(fd = GetSubTypeFeatureDefn_GCIO(*theSubType))) - { - if (!(fd = OGR_FD_Create(tdst))) - { - CSLDestroy(papszFields); - return NULL; - } - - switch (GetSubTypeKind_GCIO(*theSubType)) - { - case vPoint_GCIO: - case vText_GCIO: /* FIXME : treat as point ? */ - switch (d) - { - case v3D_GCIO: - case v3DM_GCIO: - OGR_FD_SetGeomType(fd, wkbPoint25D); - break; - default: - OGR_FD_SetGeomType(fd, wkbPoint); - break; - } - break; - case vLine_GCIO: - switch (d) - { - case v3D_GCIO: - case v3DM_GCIO: - OGR_FD_SetGeomType(fd, wkbLineString25D); - break; - default: - OGR_FD_SetGeomType(fd, wkbLineString); - break; - } - break; - case vPoly_GCIO: - switch (d) - { - case v3D_GCIO: - case v3DM_GCIO: - OGR_FD_SetGeomType(fd, wkbMultiPolygon25D); - break; - default: - OGR_FD_SetGeomType(fd, wkbMultiPolygon); - break; - } - break; - default: - CSLDestroy(papszFields); - OGR_FD_Destroy(fd); - CPLError(CE_Failure, CPLE_NotSupported, - "Unknown Geoconcept type for '%s'.\n", tdst); - return NULL; - } - for (i = 1 + nbf; i < 1 + nbf + nbstf; i++) - { - theField = GetSubTypeField_GCIO(*theSubType, i); - if (!(fld = OGR_Fld_Create(GetFieldName_GCIO(theField), - OFTString))) /* FIXME */ - { - CSLDestroy(papszFields); - OGR_FD_Destroy(fd); - return NULL; - } - OGR_FD_AddFieldDefn(fd, fld); - OGR_Fld_Destroy(fld); - fld = NULL; - } - } - - /* - * the Subclass is just under parsing via _parseObject_GCIO - */ - if (buildFeature) - { - if (!(f = OGR_F_Create(fd))) - { - if (!GetSubTypeFeatureDefn_GCIO(*theSubType)) - OGR_FD_Destroy(fd); - CSLDestroy(papszFields); - return NULL; - } - OGR_F_SetFID(f, atol(papszFields[0])); /* FID */ - if (OGR_F_GetFID(f) == OGRNullFID) - { - OGR_F_SetFID(f, GetGCCurrentLinenum_GCIO(H)); - } - for (i = 1 + nbf, j = 0; i < 1 + nbf + nbstf; i++, j++) - { - /*theField= GetSubTypeField_GCIO(*theSubType,i); */ /* FIXME?*/ - if (papszFields[i][0] == '\0') - OGR_F_UnsetField(f, j); - else - OGR_F_SetFieldString(f, j, papszFields[i]); - } - } - else - { - i = 1 + nbf + nbstf; - } - CPLDebug("GEOCONCEPT", "%d %d/%d/%d/%d\n", __LINE__, i, nbf, nbstf, nbtf); - if (!(g = _buildOGRGeometry_GCIO( - Meta, *theSubType, i, (const char **)papszFields, nbtf, d, bbox))) - { - /* - * the Subclass is under reading via ReadNextFeature_GCIO - */ - if (buildFeature) - { - CSLDestroy(papszFields); - if (f) - OGR_F_Destroy(f); - return NULL; - } - } - if (buildFeature) - { - if (OGR_F_SetGeometryDirectly(f, g) != OGRERR_NONE) - { - CSLDestroy(papszFields); - if (f) - OGR_F_Destroy(f); - return NULL; - } - } - CSLDestroy(papszFields); - - /* Assign definition : */ - if (!GetSubTypeFeatureDefn_GCIO(*theSubType)) - { - SetSubTypeFeatureDefn_GCIO(*theSubType, fd); - OGR_FD_Reference(fd); - } - - /* - * returns either the built object for ReadNextFeature_GCIO or - * the feature definition for _parseObject_GCIO : - */ - return buildFeature ? f : (OGRFeatureH)fd; -} /* _buildOGRFeature_GCIO */ - -/* -------------------------------------------------------------------- */ -static GCExportFileMetadata GCIOAPI_CALL1(*) _parseObject_GCIO(GCExportFileH *H) -{ - GCExportFileMetadata *Meta; - GCSubType *theSubType; - GCDim d; - vsi_l_offset coff; - OGREnvelope bbox, *pszBbox = &bbox; - - Meta = GetGCMeta_GCIO(H); - - InitOGREnvelope_GCIO(pszBbox); - - d = vUnknown3D_GCIO; - theSubType = NULL; - coff = (vsi_l_offset)EOF; -reloop: - /* TODO: Switch to C++ casts below. */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(H) == vComType_GCIO) - { - if (_get_GCIO(H) == (vsi_l_offset)EOF) - return Meta; - goto reloop; - } - /* analyze the line according to schema : */ - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(H) == vPragma_GCIO) - { - if (strstr(GetGCCache_GCIO(H), k3DOBJECTMONO_GCIO)) - { - d = v3DM_GCIO; - coff = GetGCCurrentOffset_GCIO(H); - } - else if (strstr(GetGCCache_GCIO(H), k3DOBJECT_GCIO)) - { - d = v3D_GCIO; - coff = GetGCCurrentOffset_GCIO(H); - } - else if (strstr(GetGCCache_GCIO(H), k2DOBJECT_GCIO)) - { - d = v2D_GCIO; - coff = GetGCCurrentOffset_GCIO(H); - } - else - { - /* not an object pragma ... */ - SetGCStatus_GCIO(H, vMemoStatus_GCIO); - return Meta; - } - if (_get_GCIO(H) == (vsi_l_offset)EOF) - return Meta; - goto reloop; - } - if (coff == (vsi_l_offset)EOF) - coff = GetGCCurrentOffset_GCIO(H); - if (!_buildOGRFeature_GCIO(H, &theSubType, d, pszBbox)) - { - return NULL; - } - if (GetSubTypeBOF_GCIO(theSubType) == (vsi_l_offset)EOF) - { - SetSubTypeBOF_GCIO(theSubType, - coff); /* Begin Of Features for the Class.Subclass */ - SetSubTypeBOFLinenum_GCIO(theSubType, GetGCCurrentLinenum_GCIO(H)); - CPLDebug("GEOCONCEPT", "Feature Type [%s] starts at #%ld, line %ld\n", - GetSubTypeName_GCIO(theSubType), - (long)GetSubTypeBOF_GCIO(theSubType), - GetSubTypeBOFLinenum_GCIO(theSubType)); - } - SetSubTypeNbFeatures_GCIO(theSubType, - GetSubTypeNbFeatures_GCIO(theSubType) + 1L); - SetGCNbObjects_GCIO(H, GetGCNbObjects_GCIO(H) + 1L); - /* update bbox of both feature and file */ - SetExtentULAbscissa_GCIO(GetMetaExtent_GCIO(Meta), pszBbox->MinX); - SetExtentULOrdinate_GCIO(GetMetaExtent_GCIO(Meta), pszBbox->MaxY); - SetExtentLRAbscissa_GCIO(GetMetaExtent_GCIO(Meta), pszBbox->MaxX); - SetExtentLROrdinate_GCIO(GetMetaExtent_GCIO(Meta), pszBbox->MinY); - if (!GetSubTypeExtent_GCIO(theSubType)) - { - SetSubTypeExtent_GCIO( - theSubType, - CreateExtent_GCIO(HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL)); - } - SetExtentULAbscissa_GCIO(GetSubTypeExtent_GCIO(theSubType), pszBbox->MinX); - SetExtentULOrdinate_GCIO(GetSubTypeExtent_GCIO(theSubType), pszBbox->MaxY); - SetExtentLRAbscissa_GCIO(GetSubTypeExtent_GCIO(theSubType), pszBbox->MaxX); - SetExtentLROrdinate_GCIO(GetSubTypeExtent_GCIO(theSubType), pszBbox->MinY); - if (d == vUnknown3D_GCIO && - GetSubTypeDim_GCIO(theSubType) == vUnknown3D_GCIO) - { - /* FIXME ? */ -#ifdef notdef - switch (d) - { - case v3DM_GCIO: - case v3D_GCIO: - SetSubTypeDim_GCIO(theSubType, v3D_GCIO); - break; - default: -#endif - SetSubTypeDim_GCIO(theSubType, v2D_GCIO); -#ifdef notdef - break; - } -#endif - } - /*d= vUnknown3D_GCIO;*/ - theSubType = NULL; - - return Meta; -} /* _parseObject_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileH GCIOAPI_CALL1(*) - Open_GCIO(const char *pszGeoconceptFile, const char *ext, /* gxt if NULL */ - const char *mode, const char *gctPath /* if !NULL, mode=w */ - ) -{ - GCExportFileH *hGXT; - - CPLDebug( - "GEOCONCEPT", "filename '%s' - '%s' - mode '%s' - config path '%s'", - pszGeoconceptFile, ext ? ext : "gxt", mode, gctPath ? gctPath : "???"); - - if (!(hGXT = _Create_GCIO(pszGeoconceptFile, ext, mode))) - { - return NULL; - } - - if (GetGCMode_GCIO(hGXT) == vUpdateAccess_GCIO) - { - VSILFILE *h; - - /* file must exists ... */ - char *pszTmp = CPLStrdup(CPLFormFilename(GetGCPath_GCIO(hGXT), - GetGCBasename_GCIO(hGXT), - GetGCExtension_GCIO(hGXT))); - if (!(h = VSIFOpenL(pszTmp, "rt"))) - { - _Destroy_GCIO(&hGXT, FALSE); - CPLFree(pszTmp); - return NULL; - } - CPLFree(pszTmp); - VSIFCloseL(h); - } - - char *pszTmp = CPLStrdup(CPLFormFilename(GetGCPath_GCIO(hGXT), - GetGCBasename_GCIO(hGXT), - GetGCExtension_GCIO(hGXT))); - SetGCHandle_GCIO(hGXT, VSIFOpenL(pszTmp, mode)); - CPLFree(pszTmp); - if (!GetGCHandle_GCIO(hGXT)) - { - _Destroy_GCIO(&hGXT, FALSE); - return NULL; - } - - if (GetGCMode_GCIO(hGXT) == vWriteAccess_GCIO) - { - if (gctPath != NULL) - { - /* load Metadata */ - GCExportFileH *hGCT; - - hGCT = _Create_GCIO(gctPath, "gct", "-"); - pszTmp = CPLStrdup(CPLFormFilename(GetGCPath_GCIO(hGCT), - GetGCBasename_GCIO(hGCT), - GetGCExtension_GCIO(hGCT))); - SetGCHandle_GCIO(hGCT, VSIFOpenL(pszTmp, "r")); - CPLFree(pszTmp); - if (!GetGCHandle_GCIO(hGCT)) - { - CPLError(CE_Failure, CPLE_NotSupported, - "opening a Geoconcept config file '%s' failed.\n", - gctPath); - _Destroy_GCIO(&hGCT, FALSE); - _Destroy_GCIO(&hGXT, TRUE); - return NULL; - } - if (ReadConfig_GCIO(hGCT) == NULL) - { - _Destroy_GCIO(&hGCT, FALSE); - _Destroy_GCIO(&hGXT, TRUE); - return NULL; - } - SetGCMeta_GCIO(hGXT, GetGCMeta_GCIO(hGCT)); - SetGCMeta_GCIO(hGCT, NULL); - _Destroy_GCIO(&hGCT, FALSE); - SetMetaExtent_GCIO( - GetGCMeta_GCIO(hGXT), - CreateExtent_GCIO(HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL)); - } - } - else - { - /* read basic Metadata from export */ - /* read and parse the export file ... */ - if (ReadHeader_GCIO(hGXT) == NULL) - { - _Destroy_GCIO(&hGXT, FALSE); - return NULL; - } - } - /* check schema */ - if (!_checkSchema_GCIO(hGXT)) - { - _Destroy_GCIO(&hGXT, - GetGCMode_GCIO(hGXT) == vWriteAccess_GCIO ? TRUE : FALSE); - return NULL; - } - - CPLDebug("GEOCONCEPT", - "Export =(\n" - " Path : %s\n" - " Basename : %s\n" - " Extension : %s\n" - " Mode : %s\n" - " Status : %s\n" - ")", - GetGCPath_GCIO(hGXT), GetGCBasename_GCIO(hGXT), - GetGCExtension_GCIO(hGXT), - GCAccessMode2str_GCIO(GetGCMode_GCIO(hGXT)), - GCAccessStatus2str_GCIO(GetGCStatus_GCIO(hGXT))); - - return hGXT; -} /* Open_GCIO */ - -/* -------------------------------------------------------------------- */ -void GCIOAPI_CALL Close_GCIO(GCExportFileH **hGXT) -{ - _Destroy_GCIO(hGXT, FALSE); -} /* Close_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileH GCIOAPI_CALL1(*) - Rewind_GCIO(GCExportFileH *hGXT, GCSubType *theSubType) -{ - if (hGXT) - { - if (GetGCHandle_GCIO(hGXT)) - { - if (!theSubType) - { - VSIRewindL(GetGCHandle_GCIO(hGXT)); - SetGCCurrentLinenum_GCIO(hGXT, 0L); - } - else - { - if (VSIFSeekL(GetGCHandle_GCIO(hGXT), - GetSubTypeBOF_GCIO(theSubType), SEEK_SET) == 0) - SetGCCurrentLinenum_GCIO( - hGXT, GetSubTypeBOFLinenum_GCIO(theSubType)); - } - SetGCStatus_GCIO(hGXT, vNoStatus_GCIO); - } - } - return hGXT; -} /* Rewind_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileH GCIOAPI_CALL1(*) FFlush_GCIO(GCExportFileH *hGXT) -{ - if (hGXT) - { - if (GetGCHandle_GCIO(hGXT)) - { - VSIFFlushL(GetGCHandle_GCIO(hGXT)); - } - } - return hGXT; -} /* FFlush_GCIO */ - -#ifdef unused -/* -------------------------------------------------------------------- */ -GCAccessMode GCIOAPI_CALL GetMode_GCIO(GCExportFileH *hGXT) -{ - return hGXT ? GetGCMode_GCIO(hGXT) : vUnknownAccessMode_GCIO; -} /* GetMode_GCIO */ -#endif - -/* -------------------------------------------------------------------- */ -GCSubType GCIOAPI_CALL1(*) - AddSubType_GCIO(GCExportFileH *H, const char *typName, - const char *subtypName, long id, GCTypeKind knd, GCDim sys) -{ - int whereClass; - GCType *theClass; - GCSubType *theSubType; - CPLList *L; - - if ((whereClass = _findTypeByName_GCIO(H, typName)) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "failed to find a Geoconcept type for '%s.%s#%ld'.\n", typName, - subtypName, id); - return NULL; - } - - theClass = _getType_GCIO(H, whereClass); - if (theClass == NULL) - return NULL; - if (GetTypeSubtypes_GCIO(theClass)) - { - if (_findSubTypeByName_GCIO(theClass, subtypName) != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept subtype '%s.%s#%ld' already exists.\n", - typName, subtypName, id); - return NULL; - } - } - - if (!(theSubType = _CreateSubType_GCIO(subtypName, id, knd, sys))) - { - return NULL; - } - if ((L = CPLListAppend(GetTypeSubtypes_GCIO(theClass), theSubType)) == NULL) - { - _DestroySubType_GCIO(&theSubType); - CPLError(CE_Failure, CPLE_OutOfMemory, - "failed to add a Geoconcept subtype for '%s.%s#%ld'.\n", - typName, subtypName, id); - return NULL; - } - SetTypeSubtypes_GCIO(theClass, L); - SetSubTypeType_GCIO(theSubType, theClass); - - CPLDebug("GEOCONCEPT", "SubType '%s.%s#%ld' added.", typName, subtypName, - id); - - return theSubType; -} /* AddSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _dropSubType_GCIO(GCSubType **theSubType) -{ - GCType *theClass; - int where; - - if (!theSubType || !(*theSubType)) - return; - if (!(theClass = GetSubTypeType_GCIO(*theSubType))) - return; - if ((where = _findSubTypeByName_GCIO( - theClass, GetSubTypeName_GCIO(*theSubType))) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, "subtype %s does not exist.\n", - GetSubTypeName_GCIO(*theSubType) - ? GetSubTypeName_GCIO(*theSubType) - : "''"); - return; - } - CPLListRemove(GetTypeSubtypes_GCIO(theClass), where); - _DestroySubType_GCIO(theSubType); - - return; -} /* _dropSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -GCType GCIOAPI_CALL1(*) - AddType_GCIO(GCExportFileH *H, const char *typName, long id) -{ - GCType *theClass; - CPLList *L; - - if (_findTypeByName_GCIO(H, typName) != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, "type %s already exists.\n", - typName); - return NULL; - } - - if (!(theClass = _CreateType_GCIO(typName, id))) - { - return NULL; - } - if ((L = CPLListAppend(GetMetaTypes_GCIO(GetGCMeta_GCIO(H)), theClass)) == - NULL) - { - _DestroyType_GCIO(&theClass); - CPLError(CE_Failure, CPLE_OutOfMemory, - "failed to add a Geoconcept type for '%s#%ld'.\n", typName, - id); - return NULL; - } - SetMetaTypes_GCIO(GetGCMeta_GCIO(H), L); - - CPLDebug("GEOCONCEPT", "Type '%s#%ld' added.", typName, id); - - return theClass; -} /* AddType_GCIO */ - -/* -------------------------------------------------------------------- */ -static void GCIOAPI_CALL _dropType_GCIO(GCExportFileH *H, GCType **theClass) -{ - int where; - - if (!theClass || !(*theClass)) - return; - if ((where = _findTypeByName_GCIO(H, GetTypeName_GCIO(*theClass))) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, "type %s does not exist.\n", - GetTypeName_GCIO(*theClass) ? GetTypeName_GCIO(*theClass) - : "''"); - return; - } - CPLListRemove(GetMetaTypes_GCIO(GetGCMeta_GCIO(H)), where); - _DestroyType_GCIO(theClass); - - return; -} /* _dropType_GCIO */ - -/* -------------------------------------------------------------------- */ -GCField GCIOAPI_CALL1(*) - AddTypeField_GCIO(GCExportFileH *H, const char *typName, - int where, /* -1 : in the end */ - const char *name, long id, GCTypeKind knd, - const char *extra, const char *enums) -{ - int whereClass; - GCType *theClass; - GCField *theField; - CPLList *L; - const char *normName; - - if ((whereClass = _findTypeByName_GCIO(H, typName)) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "failed to find a Geoconcept type for '%s@%s#%ld'.\n", typName, - name, id); - return NULL; - } - theClass = _getType_GCIO(H, whereClass); - if (theClass == NULL) - { - return NULL; - } - normName = _NormalizeFieldName_GCIO(name); - if (_findFieldByName_GCIO(GetTypeFields_GCIO(theClass), normName) != -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "field '%s@%s#%ld' already exists.\n", typName, name, id); - return NULL; - } - - if (!(theField = _CreateField_GCIO(normName, id, knd, extra, enums))) - { - return NULL; - } - if (where == -1 || - (where == 0 && CPLListCount(GetTypeFields_GCIO(theClass)) == 0)) - { - L = CPLListAppend(GetTypeFields_GCIO(theClass), theField); - } - else - { - L = CPLListInsert(GetTypeFields_GCIO(theClass), theField, where); - } - if (!L) - { - _DestroyField_GCIO(&theField); - CPLError(CE_Failure, CPLE_OutOfMemory, - "failed to add a Geoconcept field for '%s@%s#%ld'.\n", typName, - name, id); - return NULL; - } - SetTypeFields_GCIO(theClass, L); - - CPLDebug("GEOCONCEPT", "Field '%s@%s#%ld' added.", typName, name, id); - - return theField; -} /* AddTypeField_GCIO */ - -/* -------------------------------------------------------------------- */ -GCField GCIOAPI_CALL1(*) - AddSubTypeField_GCIO(GCExportFileH *H, const char *typName, - const char *subtypName, - int where, /* -1 : in the end */ - const char *name, long id, GCTypeKind knd, - const char *extra, const char *enums) -{ - int whereClass, whereSubType; - GCType *theClass; - GCSubType *theSubType; - GCField *theField; - CPLList *L; - const char *normName; - - if ((whereClass = _findTypeByName_GCIO(H, typName)) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "failed to find a Geoconcept type for '%s.%s@%s#%ld'.\n", - typName, subtypName, name, id); - return NULL; - } - theClass = _getType_GCIO(H, whereClass); - - if ((whereSubType = _findSubTypeByName_GCIO(theClass, subtypName)) == -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "failed to find a Geoconcept subtype for '%s.%s@%s#%ld'.\n", - typName, subtypName, name, id); - return NULL; - } - theSubType = _getSubType_GCIO(theClass, whereSubType); - if (theSubType == NULL) - { - return NULL; - } - - normName = _NormalizeFieldName_GCIO(name); - if (_findFieldByName_GCIO(GetSubTypeFields_GCIO(theSubType), normName) != - -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "field '%s.%s@%s#%ld' already exists.\n", typName, subtypName, - name, id); - return NULL; - } - - if (!(theField = _CreateField_GCIO(normName, id, knd, extra, enums))) - { - return NULL; - } - if (where == -1 || - (where == 0 && CPLListCount(GetSubTypeFields_GCIO(theSubType)) == 0)) - { - L = CPLListAppend(GetSubTypeFields_GCIO(theSubType), theField); - } - else - { - L = CPLListInsert(GetSubTypeFields_GCIO(theSubType), theField, where); - } - if (!L) - { - _DestroyField_GCIO(&theField); - CPLError(CE_Failure, CPLE_OutOfMemory, - "failed to add a Geoconcept field for '%s.%s@%s#%ld'.\n", - typName, subtypName, name, id); - return NULL; - } - SetSubTypeFields_GCIO(theSubType, L); - - CPLDebug("GEOCONCEPT", "Field '%s.%s@%s#%ld' added.", typName, subtypName, - name, id); - - return theField; -} /* AddSubTypeField_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigField_GCIO(GCExportFileH *hGCT) -{ - int bEOF; - char *k; - char n[kItemSize_GCIO] = {0}; - char x[kExtraSize_GCIO] = {0}; - char e[kExtraSize_GCIO] = {0}; - const char *normName; - long id; - GCTypeKind knd; - CPLList *L; - GCField *theField; - - bEOF = 0; - n[0] = '\0'; - x[0] = '\0'; - e[0] = '\0'; - id = UNDEFINEDID_GCIO; - knd = vUnknownItemType_GCIO; - theField = NULL; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndField_GCIO) != NULL) - { - bEOF = 1; - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - knd == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, "Missing %s.\n", - n[0] == '\0' ? "Name" - : id == UNDEFINEDID_GCIO ? "ID" - : "Kind"); - goto onError; - } - normName = _NormalizeFieldName_GCIO(n); - if (_findFieldByName_GCIO( - GetMetaFields_GCIO(GetGCMeta_GCIO(hGCT)), normName) != - -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "field '@%s#%ld' already exists.\n", n, id); - goto onError; - } - if (!(theField = _CreateField_GCIO(normName, id, knd, x, e))) - { - goto onError; - } - if ((L = CPLListAppend(GetMetaFields_GCIO(GetGCMeta_GCIO(hGCT)), - theField)) == NULL) - { - _DestroyField_GCIO(&theField); - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to add a Geoconcept field for '@%s#%ld'.\n", n, - id); - goto onError; - } - SetMetaFields_GCIO(GetGCMeta_GCIO(hGCT), L); - break; - } - - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigName_GCIO)) != NULL) - { - if (n[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(n, k, kItemSize_GCIO - 1); - n[kItemSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigID_GCIO)) != - NULL) - { - if (id != UNDEFINEDID_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (sscanf(k, "%ld", &id) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigKind_GCIO)) != - NULL) - { - if (knd != vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((knd = str2GCTypeKind_GCIO(k)) == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigExtra_GCIO)) != - NULL || - (k = strstr(GetGCCache_GCIO(hGCT), - kConfigExtraText_GCIO)) != NULL) - { - if (x[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(x, k, kExtraSize_GCIO - 1); - x[kExtraSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigList_GCIO)) != - NULL) - { - if (e[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(e, k, kExtraSize_GCIO - 1); - e[kExtraSize_GCIO - 1] = '\0'; - } - else - { /* Skipping ... */ - } - - continue; - } - onError: - return OGRERR_CORRUPT_DATA; - } - if (bEOF != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config field end block %s not found.\n", - kConfigEndField_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigField_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigFieldType_GCIO(GCExportFileH *hGCT, - GCType *theClass) -{ - int bEOF; - char *k; - char n[kItemSize_GCIO] = {0}; - char x[kExtraSize_GCIO] = {0}; - char e[kExtraSize_GCIO] = {0}; - long id; - GCTypeKind knd; - - bEOF = 0; - n[0] = '\0'; - x[0] = '\0'; - e[0] = '\0'; - id = UNDEFINEDID_GCIO; - knd = vUnknownItemType_GCIO; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - /* TODO: Switch to C++ casts below. */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndField_GCIO) != NULL) - { - bEOF = 1; - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - knd == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, "Missing %s.\n", - n[0] == '\0' ? "Name" - : id == UNDEFINEDID_GCIO ? "ID" - : "Kind"); - goto onError; - } - if (AddTypeField_GCIO(hGCT, GetTypeName_GCIO(theClass), -1, n, - id, knd, x, e) == NULL) - { - goto onError; - } - break; - } - - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigName_GCIO)) != NULL) - { - if (n[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(n, k, kItemSize_GCIO - 1); - n[kItemSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigID_GCIO)) != - NULL) - { - if (id != UNDEFINEDID_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (sscanf(k, "%ld", &id) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigKind_GCIO)) != - NULL) - { - if (knd != vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((knd = str2GCTypeKind_GCIO(k)) == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigExtra_GCIO)) != - NULL || - (k = strstr(GetGCCache_GCIO(hGCT), - kConfigExtraText_GCIO)) != NULL) - { - if (x[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(x, k, kExtraSize_GCIO - 1); - x[kExtraSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigList_GCIO)) != - NULL) - { - if (e[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(e, k, kExtraSize_GCIO - 1); - e[kExtraSize_GCIO - 1] = '\0'; - } - else - { /* Skipping ... */ - } - - continue; - } - onError: - return OGRERR_CORRUPT_DATA; - } - if (bEOF != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config field end block %s not found.\n", - kConfigEndField_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigFieldType_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigFieldSubType_GCIO(GCExportFileH *hGCT, - GCType *theClass, - GCSubType *theSubType) -{ - int bEOF; - char *k; - char n[kItemSize_GCIO] = {0}; - char x[kExtraSize_GCIO] = {0}; - char e[kExtraSize_GCIO] = {0}; - long id; - GCTypeKind knd; - - bEOF = 0; - n[0] = '\0'; - x[0] = '\0'; - e[0] = '\0'; - id = UNDEFINEDID_GCIO; - knd = vUnknownItemType_GCIO; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndField_GCIO) != NULL) - { - bEOF = 1; - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - knd == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, "Missing %s.\n", - n[0] == '\0' ? "Name" - : id == UNDEFINEDID_GCIO ? "ID" - : "Kind"); - goto onError; - } - if (AddSubTypeField_GCIO(hGCT, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), -1, n, - id, knd, x, e) == NULL) - { - goto onError; - } - break; - } - - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigName_GCIO)) != NULL) - { - if (n[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(n, k, kItemSize_GCIO - 1); - n[kItemSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigID_GCIO)) != - NULL) - { - if (id != UNDEFINEDID_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (sscanf(k, "%ld", &id) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigKind_GCIO)) != - NULL) - { - if (knd != vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((knd = str2GCTypeKind_GCIO(k)) == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigExtra_GCIO)) != - NULL || - (k = strstr(GetGCCache_GCIO(hGCT), - kConfigExtraText_GCIO)) != NULL) - { - if (x[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid extra information found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(x, k, kExtraSize_GCIO - 1); - x[kExtraSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigList_GCIO)) != - NULL) - { - if (e[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid List found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(e, k, kExtraSize_GCIO - 1); - e[kExtraSize_GCIO - 1] = '\0'; - } - else - { /* Skipping ... */ - } - - continue; - } - onError: - return OGRERR_CORRUPT_DATA; - } - if (bEOF != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config field end block %s not found.\n", - kConfigEndField_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigFieldSubType_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigSubTypeType_GCIO(GCExportFileH *hGCT, - GCType *theClass) -{ - int eost, res; - char *k; - char n[kItemSize_GCIO] = {0}; - long id; - GCTypeKind knd; - GCDim sys; - GCSubType *theSubType; - - eost = 0; - n[0] = '\0'; - id = UNDEFINEDID_GCIO; - knd = vUnknownItemType_GCIO; - sys = v2D_GCIO; - theSubType = NULL; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndSubType_GCIO) != NULL) - { - eost = 1; - break; - } - res = OGRERR_NONE; - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigName_GCIO)) != NULL) - { - if (n[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(n, k, kItemSize_GCIO - 1); - n[kItemSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigID_GCIO)) != - NULL) - { - if (id != UNDEFINEDID_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (sscanf(k, "%ld", &id) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigKind_GCIO)) != - NULL) - { - if (knd != vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((knd = str2GCTypeKind_GCIO(k)) == vUnknownItemType_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported Kind found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfig3D_GCIO)) != - NULL) - { - if (sys != vUnknown3D_GCIO && sys != v2D_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Dimension found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Dimension found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((sys = str2GCDim(k)) == vUnknown3D_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported Dimension found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginField_GCIO) != - NULL) - { - if (theSubType == NULL) - { - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - knd == vUnknownItemType_GCIO || sys == vUnknown3D_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, "Missing %s.\n", - n[0] == '\0' ? "Name" - : id == UNDEFINEDID_GCIO ? "ID" - : knd == vUnknownItemType_GCIO ? "Kind" - : "3D"); - goto onError; - } - if ((theSubType = - AddSubType_GCIO(hGCT, GetTypeName_GCIO(theClass), - n, id, knd, sys)) == NULL) - { - goto onError; - } - } - res = _readConfigFieldSubType_GCIO(hGCT, theClass, theSubType); - } - else - { /* Skipping ... */ - res = OGRERR_NONE; - } - if (res != OGRERR_NONE) - { - goto onError; - } - continue; - } - onError: - if (theSubType) - { - _dropSubType_GCIO(&theSubType); - } - return OGRERR_CORRUPT_DATA; - } - if (eost != 1) - { - if (theSubType) - { - _dropSubType_GCIO(&theSubType); - } - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config subtype end block %s not found.\n", - kConfigEndSubType_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigSubTypeType_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigType_GCIO(GCExportFileH *hGCT) -{ - int eot, res; - char *k; - char n[kItemSize_GCIO] = {0}; - long id; - GCType *theClass; - - eot = 0; - n[0] = '\0'; - id = UNDEFINEDID_GCIO; - theClass = NULL; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndType_GCIO) != NULL) - { - eot = 1; - break; - } - res = OGRERR_NONE; - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigName_GCIO)) != NULL) - { - if (n[0] != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Name found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - strncpy(n, k, kItemSize_GCIO - 1); - n[kItemSize_GCIO - 1] = '\0'; - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigID_GCIO)) != - NULL) - { - if (id != UNDEFINEDID_GCIO) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Duplicate ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (sscanf(k, "%ld", &id) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Not supported ID found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - } - else if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginSubType_GCIO) != - NULL) - { - if (theClass == NULL) - { - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - (theClass = AddType_GCIO(hGCT, n, id)) == NULL) - { - goto onError; - } - } - res = _readConfigSubTypeType_GCIO(hGCT, theClass); - } - else if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginField_GCIO) != - NULL) - { - if (theClass == NULL) - { - if (n[0] == '\0' || id == UNDEFINEDID_GCIO || - (theClass = AddType_GCIO(hGCT, n, id)) == NULL) - { - goto onError; - } - } - res = _readConfigFieldType_GCIO(hGCT, theClass); - } - else - { /* Skipping ... */ - res = OGRERR_NONE; - } - if (res != OGRERR_NONE) - { - goto onError; - } - continue; - } - onError: - if (theClass) - { - _dropType_GCIO(hGCT, &theClass); - } - return OGRERR_CORRUPT_DATA; - } - if (eot != 1) - { - if (theClass) - { - _dropType_GCIO(hGCT, &theClass); - } - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config type end block %s not found.\n", - kConfigEndType_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigType_GCIO */ - -/* -------------------------------------------------------------------- */ -static OGRErr GCIOAPI_CALL _readConfigMap_GCIO(GCExportFileH *hGCT) -{ - int eom; - char *k; - - eom = 0; - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndMap_GCIO) != NULL) - { - eom = 1; - break; - } - - if ((k = strstr(GetGCCache_GCIO(hGCT), kConfigUnit_GCIO)) != NULL && - strstr(GetGCCache_GCIO(hGCT), kConfigZUnit_GCIO) == NULL) - { - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Unit found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - SetMetaUnit_GCIO(GetGCMeta_GCIO(hGCT), k); - } - else if ((k = strstr(GetGCCache_GCIO(hGCT), - kConfigPrecision_GCIO)) != NULL && - strstr(GetGCCache_GCIO(hGCT), kConfigZPrecision_GCIO) == - NULL) - { - double r; - if ((k = _getHeaderValue_GCIO(k)) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Precision found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - if (CPLsscanf(k, "%lf", &r) != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid Precision found : '%s'.\n", - GetGCCache_GCIO(hGCT)); - goto onError; - } - SetMetaResolution_GCIO(GetGCMeta_GCIO(hGCT), r); - } - else - { /* Skipping ... */ - } - - continue; - } - onError: - return OGRERR_CORRUPT_DATA; - } - if (eom != 1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config map end block %s not found.\n", - kConfigEndMap_GCIO); - return OGRERR_CORRUPT_DATA; - } - - return OGRERR_NONE; -} /* _readConfigMap_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileMetadata GCIOAPI_CALL1(*) ReadConfig_GCIO(GCExportFileH *hGCT) -{ - int eoc, res, it, nt; - int i, n, il, nl, ll; - int is, ns; - char l[kExtraSize_GCIO]; - const char *v; - GCField *theField; - GCSubType *theSubType; - GCType *theClass; - CPLList *e, *es, *et; - GCExportFileMetadata *Meta; - - eoc = 0; - if (_get_GCIO(hGCT) == (vsi_l_offset)EOF) - { - return NULL; - } - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) != vHeader_GCIO && - strstr(GetGCCache_GCIO(hGCT), kConfigBeginConfig_GCIO) == NULL) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config begin block %s not found.\n", - kConfigBeginConfig_GCIO); - return NULL; - } - SetGCMeta_GCIO(hGCT, CreateHeader_GCIO()); - if ((Meta = GetGCMeta_GCIO(hGCT)) == NULL) - { - return NULL; - } - while (_get_GCIO(hGCT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGCT) == vHeader_GCIO) - { - if (strstr(GetGCCache_GCIO(hGCT), kConfigEndConfig_GCIO) != NULL) - { - eoc = 1; - break; - } - - if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginMap_GCIO) != NULL) - { - res = _readConfigMap_GCIO(hGCT); - } - else if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginType_GCIO) != - NULL) - { - res = _readConfigType_GCIO(hGCT); - } - else if (strstr(GetGCCache_GCIO(hGCT), kConfigBeginField_GCIO) != - NULL) - { - res = _readConfigField_GCIO(hGCT); - } - else - { /* Skipping : Version, Origin, ... */ - res = OGRERR_NONE; - } - if (res != OGRERR_NONE) - { - goto onError; - } - continue; - } - onError: - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGCT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGCT)); - return NULL; - } - if (eoc != 1) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGCT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept config end block %s not found.\n", - kConfigEndConfig_GCIO); - return NULL; - } - - if ((nt = CPLListCount(GetMetaTypes_GCIO(Meta))) == 0) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGCT))); - CPLError(CE_Failure, CPLE_AppDefined, "No types found.\n"); - return NULL; - } - /* for each general fields add it on top of types' fields list */ - if (GetMetaFields_GCIO(Meta)) - { - if ((n = CPLListCount(GetMetaFields_GCIO(Meta))) > 0) - { - for (i = n - 1; i >= 0; i--) - { - if ((e = CPLListGet(GetMetaFields_GCIO(Meta), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - l[0] = '\0'; - ll = 0; - if ((nl = CSLCount(GetFieldList_GCIO(theField))) > 0) - { - for (il = 0; il < nl; il++) - { - v = CSLGetField(GetFieldList_GCIO(theField), - il); - snprintf(l + ll, kExtraSize_GCIO - ll - 1, - "%s;", v); - l[kExtraSize_GCIO - 1] = '\0'; - ll += (int)strlen(v); - } - } - for (it = 0; it < nt; it++) - { - if ((et = CPLListGet(GetMetaTypes_GCIO(Meta), it))) - { - if ((theClass = (GCType *)CPLListGetData(et))) - { - if (AddTypeField_GCIO( - hGCT, GetTypeName_GCIO(theClass), 0, - GetFieldName_GCIO(theField), - GetFieldID_GCIO(theField), - GetFieldKind_GCIO(theField), - GetFieldExtra_GCIO(theField), - l) == NULL) - { - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - } - } - } - } - } - for (i = n - 1; i >= 0; i--) - { - if ((e = CPLListGet(GetMetaFields_GCIO(Meta), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - _DestroyField_GCIO(&theField); - } - } - } - } - CPLListDestroy(GetMetaFields_GCIO(Meta)); - SetMetaFields_GCIO(Meta, NULL); - } - - /* for each field of types add it on top of types' subtypes field list */ - for (it = 0; it < nt; it++) - { - if ((et = CPLListGet(GetMetaTypes_GCIO(Meta), it))) - { - if ((theClass = (GCType *)CPLListGetData(et))) - { - if ((ns = CPLListCount(GetTypeSubtypes_GCIO(theClass))) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "No subtypes found for type %s.\n", - GetTypeName_GCIO(theClass)); - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGCT))); - return NULL; - } - for (is = 0; is < ns; is++) - { - if ((es = CPLListGet(GetTypeSubtypes_GCIO(theClass), is))) - { - if ((theSubType = (GCSubType *)CPLListGetData(es))) - { - if (_findFieldByName_GCIO( - GetTypeFields_GCIO(theClass), - kNbFields_GCIO) == -1 && - _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kNbFields_GCIO) == -1) - { - if (AddSubTypeField_GCIO( - hGCT, GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType), 0, - kNbFields_GCIO, -9999L, vIntFld_GCIO, - NULL, NULL) == NULL) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((n = CPLListCount( - GetTypeFields_GCIO(theClass))) > 0) - { - for (i = n - 1; i >= 0; i--) - { - if ((e = CPLListGet( - GetTypeFields_GCIO(theClass), i))) - { - if ((theField = - (GCField *)CPLListGetData(e))) - { - l[0] = '\0'; - ll = 0; - if ((nl = - CSLCount(GetFieldList_GCIO( - theField))) > 0) - { - for (il = 0; il < nl; il++) - { - v = CSLGetField( - GetFieldList_GCIO( - theField), - il); - snprintf(l + ll, - kExtraSize_GCIO - - ll - 1, - "%s;", v); - l[kExtraSize_GCIO - 1] = - '\0'; - ll += (int)strlen(v); - } - } - if (AddSubTypeField_GCIO( - hGCT, - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO( - theSubType), - 0, - GetFieldName_GCIO(theField), - GetFieldID_GCIO(theField), - GetFieldKind_GCIO(theField), - GetFieldExtra_GCIO( - theField), - l) == NULL) - { - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - } - } - } - } - } - } - if ((n = CPLListCount(GetTypeFields_GCIO(theClass))) > 0) - { - for (i = n - 1; i >= 0; i--) - { - if ((e = CPLListGet(GetTypeFields_GCIO(theClass), i))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - _DestroyField_GCIO(&theField); - } - } - } - } - CPLListDestroy(GetTypeFields_GCIO(theClass)); - SetTypeFields_GCIO(theClass, NULL); - } - } - } - - /* let's reorder sub-types fields : */ - for (it = 0; it < nt; it++) - { - if ((et = CPLListGet(GetMetaTypes_GCIO(Meta), it))) - { - if ((theClass = (GCType *)CPLListGetData(et))) - { - ns = CPLListCount(GetTypeSubtypes_GCIO(theClass)); - for (is = 0; is < ns; is++) - { - if ((es = CPLListGet(GetTypeSubtypes_GCIO(theClass), is))) - { - if ((theSubType = (GCSubType *)CPLListGetData(es))) - { - CPLList *orderedFields = NULL; - if ((n = CPLListCount( - GetSubTypeFields_GCIO(theSubType))) > 0) - { - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kIdentifier_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kClass_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kSubclass_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kName_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kNbFields_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - for (i = 0; i < n; i++) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!IsPrivateField_GCIO( - (GCField *)CPLListGetData(e))) - { - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData( - e)))) - { - CPLError(CE_Failure, - CPLE_OutOfMemory, - "failed to arrange " - "Geoconcept subtype " - "'%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO( - theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kX_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kY_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kXP_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kYP_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kGraphics_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - if ((i = _findFieldByName_GCIO( - GetSubTypeFields_GCIO(theSubType), - kAngle_GCIO)) != -1) - { - e = CPLListGet( - GetSubTypeFields_GCIO(theSubType), i); - if (!(orderedFields = CPLListAppend( - orderedFields, - (GCField *)CPLListGetData(e)))) - { - CPLError( - CE_Failure, CPLE_OutOfMemory, - "failed to arrange Geoconcept " - "subtype '%s.%s' fields list.\n", - GetTypeName_GCIO(theClass), - GetSubTypeName_GCIO(theSubType)); - DestroyHeader_GCIO( - &(GetGCMeta_GCIO(hGCT))); - return NULL; - } - } - CPLListDestroy( - GetSubTypeFields_GCIO(theSubType)); - SetSubTypeFields_GCIO(theSubType, - orderedFields); - } - } - } - } - } - } - } - - CPLDebug("GEOCONCEPT", - "Metadata = (\n" - " nb Types : %d\n" - " Charset : %s\n" - " Delimiter : 0x%x\n" - " Unit : %s\n" - " Resolution : %g\n" - " Quoted-Text : %s\n" - " Format : %s\n" - " CoordSystemID : %d; TimeZoneValue : %d\n" - ")", - CPLListCount(GetMetaTypes_GCIO(Meta)), - GCCharset2str_GCIO(GetMetaCharset_GCIO(Meta)), - GetMetaDelimiter_GCIO(Meta), GetMetaUnit_GCIO(Meta), - GetMetaResolution_GCIO(Meta), - GetMetaQuotedText_GCIO(Meta) ? "yes" : "no", - GetMetaFormat_GCIO(Meta) == 1 ? "relative" : "absolute", - GetMetaSysCoord_GCIO(Meta) - ? GetSysCoordSystemID_GCSRS(GetMetaSysCoord_GCIO(Meta)) - : -1, - GetMetaSysCoord_GCIO(Meta) - ? GetSysCoordTimeZone_GCSRS(GetMetaSysCoord_GCIO(Meta)) - : -1); - - return Meta; -} /* ReadConfig_GCIO */ - -/* -------------------------------------------------------------------- */ -static VSILFILE GCIOAPI_CALL1(*) - _writeFieldsPragma_GCIO(GCSubType *theSubType, VSILFILE *gc, char delim) -{ - int nF, iF; - GCField *theField; - CPLList *e; - - VSIFPrintfL( - gc, "%s%s Class=%s;Subclass=%s;Kind=%d;Fields=", kPragma_GCIO, - kMetadataFIELDS_GCIO, GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType)), - GetSubTypeName_GCIO(theSubType), (int)GetSubTypeKind_GCIO(theSubType)); - if ((nF = CPLListCount(GetSubTypeFields_GCIO(theSubType))) > 0) - { - for (iF = 0; iF < nF; iF++) - { - if ((e = CPLListGet(GetSubTypeFields_GCIO(theSubType), iF))) - { - if ((theField = (GCField *)CPLListGetData(e))) - { - if (iF > 0) - VSIFPrintfL(gc, "%c", delim); - if (IsPrivateField_GCIO(theField)) - { - VSIFPrintfL(gc, "%s%s", kPrivate_GCIO, - GetFieldName_GCIO(theField) + 1); - } - else - { - VSIFPrintfL(gc, "%s%s", kPublic_GCIO, - GetFieldName_GCIO(theField)); - } - } - } - } - } - VSIFPrintfL(gc, "\n"); - SetSubTypeHeaderWritten_GCIO(theSubType, TRUE); - - return gc; -} /* _writeFieldsPragma_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileH GCIOAPI_CALL1(*) WriteHeader_GCIO(GCExportFileH *H) -{ - GCExportFileMetadata *Meta; - int nT, iT, nS, iS; - GCSubType *theSubType; - GCType *theClass; - CPLList *e; - VSILFILE *gc; - - /* FIXME : howto change default values ? */ - /* there seems to be no ways in Geoconcept to change them ... */ - Meta = GetGCMeta_GCIO(H); - gc = GetGCHandle_GCIO(H); - if (GetMetaVersion_GCIO(Meta)) - { - VSIFPrintfL(gc, "%s%s %s\n", kPragma_GCIO, kMetadataVERSION_GCIO, - GetMetaVersion_GCIO(Meta)); - } - VSIFPrintfL(gc, "%s%s \"%s\"\n", kPragma_GCIO, kMetadataDELIMITER_GCIO, - _metaDelimiter2str_GCIO(GetMetaDelimiter_GCIO(Meta))); - VSIFPrintfL(gc, "%s%s \"%s\"\n", kPragma_GCIO, kMetadataQUOTEDTEXT_GCIO, - GetMetaQuotedText_GCIO(Meta) ? "yes" : "no"); - VSIFPrintfL(gc, "%s%s %s\n", kPragma_GCIO, kMetadataCHARSET_GCIO, - GCCharset2str_GCIO(GetMetaCharset_GCIO(Meta))); - if (strcmp(GetMetaUnit_GCIO(Meta), "deg") == 0 || - strcmp(GetMetaUnit_GCIO(Meta), "deg.min") == 0 || - strcmp(GetMetaUnit_GCIO(Meta), "rad") == 0 || - strcmp(GetMetaUnit_GCIO(Meta), "gr") == 0) - { - VSIFPrintfL(gc, "%s%s Angle:%s\n", kPragma_GCIO, kMetadataUNIT_GCIO, - GetMetaUnit_GCIO(Meta)); - } - else - { - VSIFPrintfL(gc, "%s%s Distance:%s\n", kPragma_GCIO, kMetadataUNIT_GCIO, - GetMetaUnit_GCIO(Meta)); - } - VSIFPrintfL(gc, "%s%s %d\n", kPragma_GCIO, kMetadataFORMAT_GCIO, - GetMetaFormat_GCIO(Meta)); - if (GetMetaSysCoord_GCIO(Meta)) - { - VSIFPrintfL(gc, "%s%s {Type: %d}", kPragma_GCIO, kMetadataSYSCOORD_GCIO, - GetSysCoordSystemID_GCSRS(GetMetaSysCoord_GCIO(Meta))); - if (GetSysCoordTimeZone_GCSRS(GetMetaSysCoord_GCIO(Meta)) != -1) - { - VSIFPrintfL(gc, ";{TimeZone: %d}", - GetSysCoordTimeZone_GCSRS(GetMetaSysCoord_GCIO(Meta))); - } - } - else - { - VSIFPrintfL(gc, "%s%s {Type: -1}", kPragma_GCIO, - kMetadataSYSCOORD_GCIO); - } - VSIFPrintfL(gc, "\n"); - - if ((nT = CPLListCount(GetMetaTypes_GCIO(Meta))) > 0) - { - for (iT = 0; iT < nT; iT++) - { - if ((e = CPLListGet(GetMetaTypes_GCIO(Meta), iT))) - { - if ((theClass = (GCType *)CPLListGetData(e))) - { - if ((nS = CPLListCount(GetTypeSubtypes_GCIO(theClass))) > 0) - { - for (iS = 0; iS < nS; iS++) - { - if ((e = CPLListGet(GetTypeSubtypes_GCIO(theClass), - iS))) - { - if ((theSubType = - (GCSubType *)CPLListGetData(e)) && - !IsSubTypeHeaderWritten_GCIO(theSubType)) - { - if (!_writeFieldsPragma_GCIO( - theSubType, gc, - GetMetaDelimiter_GCIO(Meta))) - { - return NULL; - } - } - } - } - } - } - } - } - } - - return H; -} /* WriteHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -GCExportFileMetadata GCIOAPI_CALL1(*) ReadHeader_GCIO(GCExportFileH *hGXT) -{ - GCExportFileMetadata *Meta; - - if (_get_GCIO(hGXT) == (vsi_l_offset)EOF) - { - return NULL; - } - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGXT) != vPragma_GCIO) - { - CPLDebug("GEOCONCEPT", - "Geoconcept export badly formatted :" - "%s expected.", - kPragma_GCIO); - return NULL; - } - SetGCMeta_GCIO(hGXT, CreateHeader_GCIO()); - if ((Meta = GetGCMeta_GCIO(hGXT)) == NULL) - { - return NULL; - } - SetMetaExtent_GCIO( - Meta, CreateExtent_GCIO(HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL)); - while (_get_GCIO(hGXT) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGXT) == - vComType_GCIO) - { - continue; - } - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(hGXT) == vPragma_GCIO) - { - /* try config header first ... */ - if (!_parsePragma_GCIO(hGXT)) - { - return NULL; - } - /* in case of Memo read, we try parsing an object ... */ - if (GetGCStatus_GCIO(hGXT) != vMemoStatus_GCIO) - { - continue; - } - } - /* then object ... */ - if (!_parseObject_GCIO(hGXT)) - { - return NULL; - } - } - if (CPLListCount(GetMetaTypes_GCIO(Meta)) == 0) - { - DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT))); - CPLError(CE_Failure, CPLE_AppDefined, - "Geoconcept export syntax error at line %ld.\n", - GetGCCurrentLinenum_GCIO(hGXT)); - return NULL; - } - - Rewind_GCIO(hGXT, NULL); - - CPLDebug("GEOCONCEPT", - "Metadata = (\n" - " nb Types : %d\n" - " Charset : %s\n" - " Delimiter : 0x%x\n" - " Unit : %s\n" - " Resolution : %g\n" - " Quoted-Text : %s\n" - " Format : %s\n" - " CoordSystemID : %d; TimeZoneValue : %d\n" - ")", - CPLListCount(GetMetaTypes_GCIO(Meta)), - GCCharset2str_GCIO(GetMetaCharset_GCIO(Meta)), - GetMetaDelimiter_GCIO(Meta), GetMetaUnit_GCIO(Meta), - GetMetaResolution_GCIO(Meta), - GetMetaQuotedText_GCIO(Meta) ? "yes" : "no", - GetMetaFormat_GCIO(Meta) == 1 ? "relative" : "absolute", - GetMetaSysCoord_GCIO(Meta) - ? GetSysCoordSystemID_GCSRS(GetMetaSysCoord_GCIO(Meta)) - : -1, - GetMetaSysCoord_GCIO(Meta) - ? GetSysCoordTimeZone_GCSRS(GetMetaSysCoord_GCIO(Meta)) - : -1); - - return Meta; -} /* ReadHeader_GCIO */ - -/* -------------------------------------------------------------------- */ -GCSubType GCIOAPI_CALL1(*) - FindFeature_GCIO(GCExportFileH *hGCT, const char *typDOTsubtypName) -{ - char **fe; - int whereClass, whereSubType; - GCType *theClass; - GCSubType *theSubType; - if (hGCT == NULL) - return NULL; - if (typDOTsubtypName == NULL) - return NULL; - if (!(fe = CSLTokenizeString2(typDOTsubtypName, ".", 0)) || - CSLCount(fe) != 2) - { - CSLDestroy(fe); - return NULL; - } - if ((whereClass = _findTypeByName_GCIO(hGCT, fe[0])) == -1) - { - CSLDestroy(fe); - return NULL; - } - theClass = _getType_GCIO(hGCT, whereClass); - if ((whereSubType = _findSubTypeByName_GCIO(theClass, fe[1])) == -1) - { - CSLDestroy(fe); - return NULL; - } - theSubType = _getSubType_GCIO(theClass, whereSubType); - CSLDestroy(fe); - return theSubType; -} /* FindFeature_GCIO */ - -/* -------------------------------------------------------------------- */ -int GCIOAPI_CALL FindFeatureFieldIndex_GCIO(GCSubType *theSubType, - const char *fieldName) -{ - if (theSubType == NULL) - return -1; - if (fieldName == NULL) - return -1; - return _findFieldByName_GCIO(GetSubTypeFields_GCIO(theSubType), fieldName); -} /* FindFeatureFieldIndex_GCIO */ - -/* -------------------------------------------------------------------- */ -GCField GCIOAPI_CALL1(*) - FindFeatureField_GCIO(GCSubType *theSubType, const char *fieldName) -{ - int whereField; - GCField *theField; - if ((whereField = FindFeatureFieldIndex_GCIO(theSubType, fieldName)) == -1) - { - return NULL; - } - theField = _getField_GCIO(GetSubTypeFields_GCIO(theSubType), whereField); - return theField; -} /* FindFeatureField_GCIO */ - -/* -------------------------------------------------------------------- */ -static char GCIOAPI_CALL1(*) - _escapeString_GCIO(CPL_UNUSED GCExportFileH *H, const char *theString) -{ - int l, i, o; - char *res; - if (!theString || (l = (int)strlen(theString)) == 0) - { - res = CPLStrdup(theString); - return res; - } - if ((res = (char *)CPLMalloc(l * 2 + 1))) - { - for (i = 0, o = 0; i < l; i++, o++) - { - switch (theString[i]) - { - case '\t': - res[o] = '#'; - o++; - res[o] = '#'; - break; - case '\r': - case '\n': - res[o] = '@'; - break; - default: - res[o] = theString[i]; - break; - } - } - res[o] = '\0'; - } - return res; -} /* _escapeString_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _findNextFeatureFieldToWrite_GCIO(GCSubType *theSubType, - int from, long id) -{ - GCExportFileH *H; - VSILFILE *h; - int n, i; - GCField *theField; - char *fieldName, *escapedValue, delim; - const char *quotes; - - if ((n = CountSubTypeFields_GCIO(theSubType)) == 0) - { - return WRITECOMPLETED_GCIO; - } - if (!(from < n)) - { - return WRITECOMPLETED_GCIO; - } - - H = GetSubTypeGCHandle_GCIO(theSubType); - h = GetGCHandle_GCIO(H); - /* Dimension pragma for 3DM et 3D : */ - if (from == 0) - { - if (GetSubTypeDim_GCIO(theSubType) == v3DM_GCIO) - { - if (VSIFPrintfL(h, "%s%s\n", kPragma_GCIO, k3DOBJECTMONO_GCIO) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - SetGCCurrentLinenum_GCIO(H, GetGCCurrentLinenum_GCIO(H) + 1L); - } - else if (GetSubTypeDim_GCIO(theSubType) == v3D_GCIO) - { - if (VSIFPrintfL(h, "%s%s\n", kPragma_GCIO, k3DOBJECT_GCIO) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - SetGCCurrentLinenum_GCIO(H, GetGCCurrentLinenum_GCIO(H) + 1L); - } - } - if (GetMetaQuotedText_GCIO(GetGCMeta_GCIO(H))) - { - quotes = "\""; - } - else - { - quotes = ""; - } - delim = GetMetaDelimiter_GCIO(GetGCMeta_GCIO(H)); - /* Fields are written in the same order as in the sub-type definition. */ - /* Check for Private# fields : */ - for (i = from; i < n; i++) - { - theField = GetSubTypeField_GCIO(theSubType, i); - if (!IsPrivateField_GCIO(theField)) - { - return i; /* needs a call to WriteFeatureField_GCIO() for the ith - field */ - } - fieldName = GetFieldName_GCIO(theField); - if (EQUAL(fieldName, kX_GCIO) || EQUAL(fieldName, kY_GCIO) || - EQUAL(fieldName, kXP_GCIO) || EQUAL(fieldName, kYP_GCIO) || - EQUAL(fieldName, kGraphics_GCIO) || EQUAL(fieldName, kAngle_GCIO)) - { - return GEOMETRYEXPECTED_GCIO; /* needs a call to - WriteFeatureGeometry_GCIO() now */ - } - if (EQUAL(fieldName, kIdentifier_GCIO)) - { - /* long integer which GeoConcept may use as a key for the object it - * will create. */ - /* If set to '-1', it will be ignored. */ - if (VSIFPrintfL(h, "%s%ld%s", quotes, id, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - } - else if (EQUAL(fieldName, kClass_GCIO)) - { - if (!(escapedValue = _escapeString_GCIO( - H, GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType))))) - { - return WRITEERROR_GCIO; - } - if (VSIFPrintfL(h, "%s%s%s", quotes, escapedValue, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - CPLFree(escapedValue); - return WRITEERROR_GCIO; - } - CPLFree(escapedValue); - } - else if (EQUAL(fieldName, kSubclass_GCIO)) - { - if (!(escapedValue = - _escapeString_GCIO(H, GetSubTypeName_GCIO(theSubType)))) - { - return WRITEERROR_GCIO; - } - if (VSIFPrintfL(h, "%s%s%s", quotes, escapedValue, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - CPLFree(escapedValue); - return WRITEERROR_GCIO; - } - CPLFree(escapedValue); - } - else if (EQUAL(fieldName, kName_GCIO)) - { - if (!(escapedValue = - _escapeString_GCIO(H, GetSubTypeName_GCIO(theSubType)))) - { - return WRITEERROR_GCIO; - } - if (VSIFPrintfL(h, "%s%s%s", quotes, escapedValue, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - CPLFree(escapedValue); - return WRITEERROR_GCIO; - } - CPLFree(escapedValue); - } - else if (EQUAL(fieldName, kNbFields_GCIO)) - { - if (VSIFPrintfL(h, "%s%d%s", quotes, - GetSubTypeNbFields_GCIO(theSubType), quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - } - else - { - CPLError(CE_Failure, CPLE_NotSupported, - "Writing %s field is not implemented.\n", fieldName); - return WRITEERROR_GCIO; - } - if (i != n - 1) - { - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - } - } - - return WRITECOMPLETED_GCIO; -} /* _findNextFeatureFieldToWrite_GCIO */ - -/* -------------------------------------------------------------------- */ -int GCIOAPI_CALL StartWritingFeature_GCIO(GCSubType *theSubType, long id) -{ - if (!IsSubTypeHeaderWritten_GCIO(theSubType)) - { - GCExportFileH *H; - VSILFILE *h; - - H = GetSubTypeGCHandle_GCIO(theSubType); - h = GetGCHandle_GCIO(H); - if (!_writeFieldsPragma_GCIO(theSubType, h, - GetMetaDelimiter_GCIO(GetGCMeta_GCIO(H)))) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Write Fields pragma failed for feature id %ld.\n", id); - return WRITEERROR_GCIO; - } - } - return _findNextFeatureFieldToWrite_GCIO(theSubType, 0, id); -} /* StartWritingFeature_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _writePoint_GCIO(VSILFILE *h, const char *quotes, - char delim, double x, double y, - double z, GCDim dim, GCExtent *e, - int pCS, int hCS) -{ - SetExtentULAbscissa_GCIO(e, x); - SetExtentULOrdinate_GCIO(e, y); - SetExtentLRAbscissa_GCIO(e, x); - SetExtentLROrdinate_GCIO(e, y); - if (dim == v3DM_GCIO || dim == v3D_GCIO) - { - if (VSIFPrintfL(h, "%s%.*f%s%c%s%.*f%s%c%s%.*f%s", quotes, pCS, x, - quotes, delim, quotes, pCS, y, quotes, delim, quotes, - hCS, z, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - } - else - { - if (VSIFPrintfL(h, "%s%.*f%s%c%s%.*f%s", quotes, pCS, x, quotes, delim, - quotes, pCS, y, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - } - return TRUE; -} /* _writePoint_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _writeLine_GCIO(VSILFILE *h, const char *quotes, - char delim, OGRGeometryH poArc, - GCTypeKind knd, GCDim dim, int fmt, - GCExtent *e, int pCS, int hCS) -{ - int iP, nP; - double dX, dY, dZ; - /* 1st point */ - if (!_writePoint_GCIO(h, quotes, delim, OGR_G_GetX(poArc, 0), - OGR_G_GetY(poArc, 0), OGR_G_GetZ(poArc, 0), dim, e, - pCS, hCS)) - { - return FALSE; - } - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - nP = OGR_G_GetPointCount(poArc); - if (knd == vLine_GCIO) - { - /* last point */ - if (!_writePoint_GCIO(h, quotes, delim, OGR_G_GetX(poArc, nP - 1), - OGR_G_GetY(poArc, nP - 1), - OGR_G_GetZ(poArc, nP - 1), dim, e, pCS, hCS)) - { - return FALSE; - } - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - } - /* number of remaining points : */ - if (VSIFPrintfL(h, "%s%d%s%c", quotes, nP - 1, quotes, delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - /* 2nd up to the last point ... */ - for (iP = 1; iP < nP; iP++) - { - if (fmt == 1) - { /* relative coordinates ... */ - dX = OGR_G_GetX(poArc, iP - 1) - OGR_G_GetX(poArc, iP); - dY = OGR_G_GetY(poArc, iP - 1) - OGR_G_GetY(poArc, iP); - dZ = OGR_G_GetZ(poArc, iP - 1) - OGR_G_GetZ(poArc, iP); - } - else - { /* absolute coordinates ... */ - dX = OGR_G_GetX(poArc, iP); - dY = OGR_G_GetY(poArc, iP); - dZ = OGR_G_GetZ(poArc, iP); - } - if (!_writePoint_GCIO(h, quotes, delim, dX, dY, dZ, dim, e, pCS, hCS)) - { - return FALSE; - } - if (iP != nP - 1) - { - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - } - } - return TRUE; -} /* _writeLine_GCIO */ - -/* -------------------------------------------------------------------- */ -static int GCIOAPI_CALL _writePolygon_GCIO(VSILFILE *h, const char *quotes, - char delim, OGRGeometryH poPoly, - GCDim dim, int fmt, GCExtent *e, - int pCS, int hCS) -{ - int iR, nR; - OGRGeometryH poRing; - /* - * X<>Y[<>Z]{Single Polygon{<>NrPolys=j[<>X<>Y[<>Z]<>Single Polygon]j}} - * with : - * Single Polygon = Nr points=k[<>PointX<>PointY[<>Z]]k... - */ - if ((nR = OGR_G_GetGeometryCount(poPoly)) == 0) - { - CPLError(CE_Warning, CPLE_AppDefined, - "Ignore POLYGON EMPTY in Geoconcept writer.\n"); - return TRUE; - } - poRing = OGR_G_GetGeometryRef(poPoly, 0); - if (!_writeLine_GCIO(h, quotes, delim, poRing, vPoly_GCIO, dim, fmt, e, pCS, - hCS)) - { - return FALSE; - } - /* number of interior rings : */ - if (nR > 1) - { - if (VSIFPrintfL(h, "%c%d%c", delim, nR - 1, delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - for (iR = 1; iR < nR; iR++) - { - poRing = OGR_G_GetGeometryRef(poPoly, iR); - if (!_writeLine_GCIO(h, quotes, delim, poRing, vPoly_GCIO, dim, fmt, - e, pCS, hCS)) - { - return FALSE; - } - if (iR != nR - 1) - { - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return FALSE; - } - } - } - } - return TRUE; -} /* _writePolygon_GCIO */ - -/* -------------------------------------------------------------------- */ -int GCIOAPI_CALL WriteFeatureGeometry_GCIO(GCSubType *theSubType, - OGRGeometryH poGeom) -{ - GCExportFileH *H; - VSILFILE *h; - int n, i, iAn, pCS, hCS; - const char *quotes; - char delim; - - H = GetSubTypeGCHandle_GCIO(theSubType); - h = GetGCHandle_GCIO(H); - n = CountSubTypeFields_GCIO(theSubType); - iAn = -1; - if ((i = _findFieldByName_GCIO(GetSubTypeFields_GCIO(theSubType), - kGraphics_GCIO)) == -1) - { - if ((i = _findFieldByName_GCIO(GetSubTypeFields_GCIO(theSubType), - kAngle_GCIO)) == -1) - { - i = _findFieldByName_GCIO(GetSubTypeFields_GCIO(theSubType), - kY_GCIO); - } - else - { - iAn = i; - } - } - - if (GetMetaQuotedText_GCIO(GetGCMeta_GCIO(H))) - { - quotes = "\""; - } - else - { - quotes = ""; - } - delim = GetMetaDelimiter_GCIO(GetGCMeta_GCIO(H)); - - if ((pCS = GetMetaPlanarFormat_GCIO(GetGCMeta_GCIO(H))) == 0) - { - if (OSRIsGeographic(GetMetaSRS_GCIO(GetGCMeta_GCIO(H)))) - { - pCS = kGeographicPlanarRadix; - } - else - { - pCS = kCartesianPlanarRadix; - } - SetMetaPlanarFormat_GCIO(GetGCMeta_GCIO(H), pCS); - } - - hCS = 0; - if (GetSubTypeDim_GCIO(theSubType) == v3D_GCIO && - (hCS = GetMetaHeightFormat_GCIO(GetGCMeta_GCIO(H))) == 0) - { - hCS = kElevationRadix; - SetMetaHeightFormat_GCIO(GetGCMeta_GCIO(H), hCS); - } - - switch (wkbFlatten(OGR_G_GetGeometryType(poGeom))) - { - case wkbPoint: - if (!_writePoint_GCIO(h, quotes, delim, OGR_G_GetX(poGeom, 0), - OGR_G_GetY(poGeom, 0), OGR_G_GetZ(poGeom, 0), - GetSubTypeDim_GCIO(theSubType), - GetMetaExtent_GCIO(GetGCMeta_GCIO(H)), pCS, - hCS)) - { - return WRITEERROR_GCIO; - } - break; - case wkbLineString: - if (!_writeLine_GCIO(h, quotes, delim, poGeom, vLine_GCIO, - GetSubTypeDim_GCIO(theSubType), - GetMetaFormat_GCIO(GetGCMeta_GCIO(H)), - GetMetaExtent_GCIO(GetGCMeta_GCIO(H)), pCS, - hCS)) - { - return WRITEERROR_GCIO; - } - break; - case wkbPolygon: - if (!_writePolygon_GCIO( - h, quotes, delim, poGeom, GetSubTypeDim_GCIO(theSubType), - GetMetaFormat_GCIO(GetGCMeta_GCIO(H)), - GetMetaExtent_GCIO(GetGCMeta_GCIO(H)), pCS, hCS)) - { - return WRITEERROR_GCIO; - } - break; - default: - CPLError(CE_Warning, CPLE_AppDefined, - "Geometry type %d not supported in Geoconcept, feature " - "skipped.\n", - OGR_G_GetGeometryType(poGeom)); - break; - } - /* Angle= 0 !! */ - if (iAn != -1) - { - if (VSIFPrintfL(h, "%c%s%1d%s", delim, quotes, 0, quotes) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - } - /* if it is not the last field ... */ - if (i != n - 1) - { - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - return WRITEERROR_GCIO; - } - } - - /* find out next field to write ... */ - return _findNextFeatureFieldToWrite_GCIO(theSubType, i + 1, OGRNullFID); -} /* WriteFeatureGeometry_GCIO */ - -/* -------------------------------------------------------------------- */ -int GCIOAPI_CALL WriteFeatureFieldAsString_GCIO(GCSubType *theSubType, - int iField, - const char *theValue) -{ - GCExportFileH *H; - VSILFILE *h; - int n; - const char *quotes; - char *escapedValue, delim; - GCField *theField; - - H = GetSubTypeGCHandle_GCIO(theSubType); - h = GetGCHandle_GCIO(H); - n = CountSubTypeFields_GCIO(theSubType); - if (GetMetaQuotedText_GCIO(GetGCMeta_GCIO(H))) - { - quotes = "\""; - } - else - { - quotes = ""; - } - delim = GetMetaDelimiter_GCIO(GetGCMeta_GCIO(H)); - theField = GetSubTypeField_GCIO(theSubType, iField); - if (!theField) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Attempt to write a field #%d that does not exist on feature " - "%s.%s.\n", - iField, GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType)), - GetSubTypeName_GCIO(theSubType)); - return WRITEERROR_GCIO; - } - if (!(escapedValue = _escapeString_GCIO(H, theValue))) - { - return WRITEERROR_GCIO; - } - if (VSIFPrintfL(h, "%s%s%s", quotes, escapedValue, quotes) <= 0) - { - /* it is really an error if one of the parameters is not empty ... */ - if (*quotes != '\0' || *escapedValue != '\0') - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - CPLFree(escapedValue); - return WRITEERROR_GCIO; - } - } - if (iField != n - 1) - { - if (VSIFPrintfL(h, "%c", delim) <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - CPLFree(escapedValue); - return WRITEERROR_GCIO; - } - } - CPLFree(escapedValue); - - return _findNextFeatureFieldToWrite_GCIO(theSubType, iField + 1, - OGRNullFID); -} /* WriteFeatureFieldAsString_GCIO */ - -/* -------------------------------------------------------------------- */ -void GCIOAPI_CALL StopWritingFeature_GCIO(GCSubType *theSubType) -{ - GCExportFileH *H; - - H = GetSubTypeGCHandle_GCIO(theSubType); - if (VSIFPrintfL(GetGCHandle_GCIO(H), "\n") <= 0) - { - CPLError(CE_Failure, CPLE_AppDefined, "Write failed.\n"); - } - SetSubTypeNbFeatures_GCIO(theSubType, - GetSubTypeNbFeatures_GCIO(theSubType) + 1L); - SetGCNbObjects_GCIO(H, GetGCNbObjects_GCIO(H) + 1L); - SetGCCurrentLinenum_GCIO(H, GetGCCurrentLinenum_GCIO(H) + 1L); -} /* StopWritingFeature_GCIO */ - -/* -------------------------------------------------------------------- */ -OGRFeatureH GCIOAPI_CALL ReadNextFeature_GCIO(GCSubType *theSubType) -{ - OGRFeatureH f; - GCExportFileH *H; - GCDim d; - - f = NULL; - H = GetSubTypeGCHandle_GCIO(theSubType); - if (!(GetGCMeta_GCIO(H))) - { - return NULL; - } - d = vUnknown3D_GCIO; - while (_get_GCIO(H) != (vsi_l_offset)EOF) - { - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(H) == vComType_GCIO) - { - continue; - } - /* analyze the line according to schema : */ - /* coverity[mixed_enums] */ /* FIXME ? */ - if ((enum _tIO_MetadataType_GCIO)GetGCWhatIs_GCIO(H) == vPragma_GCIO) - { - if (strstr(GetGCCache_GCIO(H), k3DOBJECTMONO_GCIO)) - { - d = v3DM_GCIO; - } - else if (strstr(GetGCCache_GCIO(H), k3DOBJECT_GCIO)) - { - d = v3D_GCIO; - } - else if (strstr(GetGCCache_GCIO(H), k2DOBJECT_GCIO)) - { - d = v2D_GCIO; - } - continue; - } - if ((f = _buildOGRFeature_GCIO(H, &theSubType, d, NULL))) - { - break; - } - d = vUnknown3D_GCIO; - } - - return f; -} /* ReadNextFeature_GCIO */ diff --git a/ogr/ogrsf_frmts/geoconcept/geoconcept.h b/ogr/ogrsf_frmts/geoconcept/geoconcept.h deleted file mode 100644 index 42093b58d6aa..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/geoconcept.h +++ /dev/null @@ -1,539 +0,0 @@ -/********************************************************************** - * $Id: geoconcept.h$ - * - * Name: geoconcept.h - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements Physical Access class. - * Language: C - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008, Even Rouault - * - * SPDX-License-Identifier: MIT - **********************************************************************/ -#ifndef GEOCONCEPT_H_INCLUDED -#define GEOCONCEPT_H_INCLUDED - -#include "cpl_port.h" -#include "cpl_list.h" -#include "cpl_vsi.h" -#include "ogr_api.h" - -#include "geoconcept_syscoord.h" - -/* From shapefil.h : */ -/* -------------------------------------------------------------------- */ -/* GCIOAPI_CALL */ -/* */ -/* The following two macros are present to allow forcing */ -/* various calling conventions on the Geoconcept API. */ -/* */ -/* To force __stdcall conventions (needed to call GCIOLib */ -/* from Visual Basic and/or Dephi I believe) the makefile could */ -/* be modified to define: */ -/* */ -/* /DGCIOAPI_CALL=__stdcall */ -/* */ -/* If it is desired to force export of the GCIOLib API without */ -/* using the geoconcept.def file, use the following definition. */ -/* */ -/* /DGCIO_DLLEXPORT */ -/* */ -/* To get both at once it will be necessary to hack this */ -/* include file to define: */ -/* */ -/* #define GCIOAPI_CALL __declspec(dllexport) __stdcall */ -/* #define GCIOAPI_CALL1 __declspec(dllexport) * __stdcall */ -/* */ -/* The complexity of the situation is partly caused by the */ -/* peculiar requirement of Visual C++ that __stdcall appear */ -/* after any "*"'s in the return value of a function while the */ -/* __declspec(dllexport) must appear before them. */ -/* -------------------------------------------------------------------- */ - -#ifdef GCIO_DLLEXPORT -#define GCIOAPI_CALL __declspec(dllexport) -#define GCIOAPI_CALL1(x) __declspec(dllexport) x -#endif - -#ifndef GCIOAPI_CALL -#define GCIOAPI_CALL -#endif - -#ifndef GCIOAPI_CALL1 -#define GCIOAPI_CALL1(x) x GCIOAPI_CALL -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define kCacheSize_GCIO 65535 -#define kCharsetMAX_GCIO 15 -#define kUnitMAX_GCIO 7 -#define kTAB_GCIO "\t" -#define kCom_GCIO "//" -#define kHeader_GCIO "//#" -#define kPragma_GCIO "//$" -#define kCartesianPlanarRadix 2 -#define kGeographicPlanarRadix 9 -#define kElevationRadix 2 - -#define kConfigBeginConfig_GCIO "SECTION CONFIG" -#define kConfigEndConfig_GCIO "ENDSECTION CONFIG" -#define kConfigBeginMap_GCIO "SECTION MAP" -#define kConfigEndMap_GCIO "ENDSECTION MAP" -#define kConfigBeginType_GCIO "SECTION TYPE" -#define kConfigBeginSubType_GCIO "SECTION SUBTYPE" -#define kConfigBeginField_GCIO "SECTION FIELD" -#define kConfigEndField_GCIO "ENDSECTION FIELD" -#define kConfigEndSubType_GCIO "ENDSECTION SUBTYPE" -#define kConfigEndType_GCIO "ENDSECTION TYPE" - -#define kConfigUnit_GCIO "Unit" -#define kConfigPrecision_GCIO "Precision" -#define kConfigName_GCIO "Name" -#define kConfigID_GCIO "ID" -#define kConfigKind_GCIO "Kind" -#define kConfig3D_GCIO "3D" -#define kConfigExtra_GCIO "Extra" -#define kConfigExtraText_GCIO "ExtraText" -#define kConfigList_GCIO "List" -/* unused config keywords : */ -#define kConfigZUnit_GCIO "ZUnit" -#define kConfigZPrecision_GCIO "ZPrecision" - -#define kMetadataVERSION_GCIO "VERSION" -#define kMetadataDELIMITER_GCIO "DELIMITER" -#define kMetadataQUOTEDTEXT_GCIO "QUOTED-TEXT" -#define kMetadataCHARSET_GCIO "CHARSET" -#define kMetadataUNIT_GCIO "UNIT" -#define kMetadataFORMAT_GCIO "FORMAT" -#define kMetadataSYSCOORD_GCIO "SYSCOORD" -#define kMetadataFIELDS_GCIO "FIELDS" -#define kPrivate_GCIO "Private#" -#define kPublic_GCIO "" -#define k3DOBJECTMONO_GCIO "3DOBJECTMONO" -#define k3DOBJECT_GCIO "3DOBJECT" -#define k2DOBJECT_GCIO "2DOBJECT" - -#define kIdentifier_GCIO "@Identifier" -#define kClass_GCIO "@Class" -#define kSubclass_GCIO "@Subclass" -#define kName_GCIO "@Name" -#define kNbFields_GCIO "@NbFields" -#define kX_GCIO "@X" -#define kY_GCIO "@Y" -#define kXP_GCIO "@XP" -#define kYP_GCIO "@YP" -#define kGraphics_GCIO "@Graphics" -#define kAngle_GCIO "@Angle" - -#define WRITEERROR_GCIO -1 -#define GEOMETRYEXPECTED_GCIO -2 -#define WRITECOMPLETED_GCIO -3 - - /* -------------------------------------------------------------------- */ - /* GCIO API Enumerations */ - /* -------------------------------------------------------------------- */ - - typedef enum _tCharset_GCIO - { - vUnknownCharset_GCIO = 0, - vANSI_GCIO, /* Windows */ - vDOS_GCIO, - vMAC_GCIO - } GCCharset; - - typedef enum _tAccessMode_GCIO - { - vUnknownAccessMode_GCIO = 0, - vNoAccess_GCIO, - vReadAccess_GCIO, - vUpdateAccess_GCIO, - vWriteAccess_GCIO - } GCAccessMode; - - typedef enum _tAccessStatus_GCIO - { - vNoStatus_GCIO, - vMemoStatus_GCIO, - vEof_GCIO - } GCAccessStatus; - - typedef enum _t3D_GCIO - { - vUnknown3D_GCIO = 0, - v2D_GCIO, - v3D_GCIO, - v3DM_GCIO - } GCDim; - - typedef enum _tItemType_GCIO - { - vUnknownItemType_GCIO = 0, - vPoint_GCIO, - vLine_GCIO, - vText_GCIO, - vPoly_GCIO, - vMemoFld_GCIO, - vIntFld_GCIO, - vRealFld_GCIO, - vLengthFld_GCIO, - vAreaFld_GCIO, - vPositionFld_GCIO, - vDateFld_GCIO, - vTimeFld_GCIO, - vChoiceFld_GCIO, - vInterFld_GCIO - } GCTypeKind; - - typedef enum _tIO_MetadataType_GCIO - { - vUnknownIO_ItemType_GCIO = 0, - vComType_GCIO, - vStdCol_GCIO, - vEndCol_GCIO, - vHeader_GCIO, - vPragma_GCIO, - vConfigBeginConfig_GCIO, - vConfigEndConfig_GCIO, - vConfigBeginMap_GCIO, - vConfigEndMap_GCIO, - vConfigBeginType_GCIO, - vConfigBeginSubType_GCIO, - vConfigBeginField_GCIO, - vConfigEndField_GCIO, - vConfigEndSubType_GCIO, - vConfigEndType_GCIO, - vMetadataDELIMITER_GCIO, - vMetadataQUOTEDTEXT_GCIO, - vMetadataCHARSET_GCIO, - vMetadataUNIT_GCIO, - vMetadataFORMAT_GCIO, - vMetadataSYSCOORD_GCIO, - vMetadataFIELDS_GCIO - } MetadataType; - - typedef enum _boolean_GCIO - { - vFALSE = 0, - vTRUE - } tBOOLEAN_GCIO; - - /* -------------------------------------------------------------------- */ - /* GCIO API Types */ - /* -------------------------------------------------------------------- */ - typedef struct _tDocFrame_GCIO GCExtent; - typedef struct _tField_GCIO GCField; - typedef struct _tSubType_GCIO GCSubType; - typedef struct _tType_GCIO GCType; - typedef struct _tExportHeader_GCIO GCExportFileMetadata; - typedef struct _GCExportFileH GCExportFileH; - - struct _tDocFrame_GCIO - { - double XUL; - double YUL; - double XLR; - double YLR; - }; - - struct _tField_GCIO - { - char *name; /* @name => private */ - char *extra; - char **enums; - long id; - GCTypeKind knd; - }; - - struct _tSubType_GCIO - { - GCExportFileH *_h; - GCType *_type; /* parent's type */ - char *name; - CPLList *fields; /* GCField */ - GCExtent *frame; - OGRFeatureDefnH _poFeaDefn; - long id; - vsi_l_offset _foff; /* offset 1st feature */ - unsigned long _flin; /* 1st ligne 1st feature */ - unsigned long _nFeatures; - GCTypeKind knd; - GCDim sys; - int _nbf; /* number of user's fields */ - int _hdrW; /* pragma field written */ - }; - - struct _tType_GCIO - { - char *name; - CPLList *subtypes; /* GCSubType */ - CPLList *fields; /* GCField */ - long id; - }; - - struct _tExportHeader_GCIO - { - CPLList *types; /* GCType */ - CPLList *fields; /* GCField */ - OGRSpatialReferenceH srs; - GCExtent *frame; - char *version; - char unit[kUnitMAX_GCIO + 1]; - double resolution; - GCCharset charset; - int quotedtext; - int format; - GCSysCoord *sysCoord; - int pCS; - int hCS; - char delimiter; - }; - - struct _GCExportFileH - { - char cache[kCacheSize_GCIO + 1]; - char *path; - char *bn; - char *ext; - VSILFILE *H; - GCExportFileMetadata *header; - vsi_l_offset coff; - unsigned long clin; - unsigned long nbObjects; - GCAccessMode mode; - GCAccessStatus status; - GCTypeKind whatIs; - }; - - /* -------------------------------------------------------------------- */ - /* GCIO API Prototypes */ - /* -------------------------------------------------------------------- */ - - const char GCIOAPI_CALL1(*) GCCharset2str_GCIO(GCCharset cs); - GCCharset GCIOAPI_CALL str2GCCharset_GCIO(const char *s); - const char GCIOAPI_CALL1(*) GCAccessMode2str_GCIO(GCAccessMode mode); - GCAccessMode str2GCAccessMode_GCIO(const char *s); - const char GCIOAPI_CALL1(*) GCAccessStatus2str_GCIO(GCAccessStatus stts); - GCAccessStatus str2GCAccessStatus_GCIO(const char *s); - const char GCIOAPI_CALL1(*) GCDim2str_GCIO(GCDim sys); - GCDim str2GCDim(const char *s); - const char GCIOAPI_CALL1(*) GCTypeKind2str_GCIO(GCTypeKind item); - GCTypeKind str2GCTypeKind_GCIO(const char *s); - - GCExportFileH GCIOAPI_CALL1(*) - Open_GCIO(const char *pszGeoconceptFile, const char *ext, - const char *mode, const char *gctPath); - void GCIOAPI_CALL Close_GCIO(GCExportFileH **hGCT); - GCExportFileH GCIOAPI_CALL1(*) - Rewind_GCIO(GCExportFileH *H, GCSubType *theSubType); - GCExportFileH GCIOAPI_CALL1(*) FFlush_GCIO(GCExportFileH *H); - - GCType GCIOAPI_CALL1(*) - AddType_GCIO(GCExportFileH *H, const char *typName, long id); - GCSubType GCIOAPI_CALL1(*) - AddSubType_GCIO(GCExportFileH *H, const char *typName, - const char *subtypName, long id, GCTypeKind knd, - GCDim sys); - GCField GCIOAPI_CALL1(*) - AddTypeField_GCIO(GCExportFileH *H, const char *typName, int where, - const char *name, long id, GCTypeKind knd, - const char *extra, const char *enums); - GCField GCIOAPI_CALL1(*) - AddSubTypeField_GCIO(GCExportFileH *H, const char *typName, - const char *subtypName, int where, - const char *name, long id, GCTypeKind knd, - const char *extra, const char *enums); - GCExportFileMetadata GCIOAPI_CALL1(*) ReadConfig_GCIO(GCExportFileH *H); - GCExportFileH GCIOAPI_CALL1(*) WriteHeader_GCIO(GCExportFileH *H); - GCExportFileMetadata GCIOAPI_CALL1(*) CreateHeader_GCIO(void); - void GCIOAPI_CALL DestroyHeader_GCIO(GCExportFileMetadata **m); - GCExtent GCIOAPI_CALL1(*) - CreateExtent_GCIO(double Xmin, double Ymin, double Xmax, double Ymax); - void GCIOAPI_CALL DestroyExtent_GCIO(GCExtent **theExtent); - GCExportFileMetadata GCIOAPI_CALL1(*) ReadHeader_GCIO(GCExportFileH *H); - GCSubType GCIOAPI_CALL1(*) - FindFeature_GCIO(GCExportFileH *H, const char *typDOTsubtypName); - int GCIOAPI_CALL FindFeatureFieldIndex_GCIO(GCSubType *theSubType, - const char *fieldName); - GCField GCIOAPI_CALL1(*) - FindFeatureField_GCIO(GCSubType *theSubType, const char *fieldName); - int GCIOAPI_CALL StartWritingFeature_GCIO(GCSubType *theSubType, long id); - int GCIOAPI_CALL WriteFeatureFieldAsString_GCIO(GCSubType *theSubType, - int iField, - const char *theValue); - int GCIOAPI_CALL WriteFeatureGeometry_GCIO(GCSubType *theSubType, - OGRGeometryH poGeom); - void GCIOAPI_CALL StopWritingFeature_GCIO(GCSubType *theSubType); - OGRFeatureH GCIOAPI_CALL ReadNextFeature_GCIO(GCSubType *theSubType); - -#define GetGCCache_GCIO(gc) (gc)->cache -#define SetGCCache_GCIO(gc, v) \ - strncpy((gc)->cache, (v), kCacheSize_GCIO), \ - (gc)->cache[kCacheSize_GCIO] = '\0'; -#define GetGCPath_GCIO(gc) (gc)->path -#define SetGCPath_GCIO(gc, v) (gc)->path = (v) -#define GetGCBasename_GCIO(gc) (gc)->bn -#define SetGCBasename_GCIO(gc, v) (gc)->bn = (v) -#define GetGCExtension_GCIO(gc) (gc)->ext -#define SetGCExtension_GCIO(gc, v) (gc)->ext = (v) -#define GetGCHandle_GCIO(gc) (gc)->H -#define SetGCHandle_GCIO(gc, v) (gc)->H = (v) -#define GetGCMeta_GCIO(gc) (gc)->header -#define SetGCMeta_GCIO(gc, v) (gc)->header = (v) -#define GetGCCurrentOffset_GCIO(gc) (gc)->coff -#define SetGCCurrentOffset_GCIO(gc, v) (gc)->coff = (v) -#define GetGCCurrentLinenum_GCIO(gc) (gc)->clin -#define SetGCCurrentLinenum_GCIO(gc, v) (gc)->clin = (v) -#define GetGCNbObjects_GCIO(gc) (gc)->nbObjects -#define SetGCNbObjects_GCIO(gc, v) (gc)->nbObjects = (v) -#define GetGCMode_GCIO(gc) (gc)->mode -#define SetGCMode_GCIO(gc, v) (gc)->mode = (v) -#define GetGCStatus_GCIO(gc) (gc)->status -#define SetGCStatus_GCIO(gc, v) (gc)->status = (v) -#define GetGCWhatIs_GCIO(gc) (gc)->whatIs -#define SetGCWhatIs_GCIO(gc, v) (gc)->whatIs = (v) - -#define GetMetaTypes_GCIO(header) (header)->types -#define SetMetaTypes_GCIO(header, v) (header)->types = (v) -#define CountMetaTypes_GCIO(header) CPLListCount((header)->types) -#define GetMetaType_GCIO(header, rank) \ - (GCType *)CPLListGetData(CPLListGet((header)->types, (rank))) -#define GetMetaFields_GCIO(header) (header)->fields -#define SetMetaFields_GCIO(header, v) (header)->fields = (v) -#define GetMetaCharset_GCIO(header) (header)->charset -#define SetMetaCharset_GCIO(header, v) (header)->charset = (v) -#define GetMetaDelimiter_GCIO(header) (header)->delimiter -#define SetMetaDelimiter_GCIO(header, v) (header)->delimiter = (v) -#define GetMetaUnit_GCIO(header) (header)->unit -#define SetMetaUnit_GCIO(header, v) \ - strncpy((header)->unit, (v), kUnitMAX_GCIO), \ - (header)->unit[kUnitMAX_GCIO] = '\0'; -#define GetMetaZUnit_GCIO(header) (header)->zUnit -#define SetMetaZUnit_GCIO(header, v) \ - strncpy((header)->zUnit, (v), kUnitMAX_GCIO), \ - (header)->zUnit[kUnitMAX_GCIO] = '\0'; -#define GetMetaResolution_GCIO(header) (header)->resolution -#define SetMetaResolution_GCIO(header, v) (header)->resolution = (v) -#define GetMetaZResolution_GCIO(header) (header)->zResolution -#define SetMetaZResolution_GCIO(header, v) (header)->zResolution = (v) -#define GetMetaQuotedText_GCIO(header) (header)->quotedtext -#define SetMetaQuotedText_GCIO(header, v) (header)->quotedtext = (v) -#define GetMetaFormat_GCIO(header) (header)->format -#define SetMetaFormat_GCIO(header, v) (header)->format = (v) -#define GetMetaSysCoord_GCIO(header) (header)->sysCoord -#define SetMetaSysCoord_GCIO(header, v) (header)->sysCoord = (v) -#define GetMetaPlanarFormat_GCIO(header) (header)->pCS -#define SetMetaPlanarFormat_GCIO(header, v) (header)->pCS = (v) -#define GetMetaHeightFormat_GCIO(header) (header)->hCS -#define SetMetaHeightFormat_GCIO(header, v) (header)->hCS = (v) - -#define GetMetaExtent_GCIO(header) (header)->frame -#define SetMetaExtent_GCIO(header, v) (header)->frame = (v) -#define GetMetaSRS_GCIO(header) (header)->srs -#define SetMetaSRS_GCIO(header, v) (header)->srs = (v) -#define GetMetaVersion_GCIO(header) (header)->version -#define SetMetaVersion_GCIO(header, v) (header)->version = (v) - -#define GetTypeName_GCIO(theClass) (theClass)->name -#define SetTypeName_GCIO(theClass, v) (theClass)->name = (v) -#define GetTypeID_GCIO(theClass) (theClass)->id -#define SetTypeID_GCIO(theClass, v) (theClass)->id = (v) -#define GetTypeSubtypes_GCIO(theClass) (theClass)->subtypes -#define SetTypeSubtypes_GCIO(theClass, v) (theClass)->subtypes = (v) -#define GetTypeFields_GCIO(theClass) (theClass)->fields -#define SetTypeFields_GCIO(theClass, v) (theClass)->fields = (v) -#define CountTypeSubtypes_GCIO(theClass) CPLListCount((theClass)->subtypes) -#define GetTypeSubtype_GCIO(theClass, rank) \ - (GCSubType *)CPLListGetData(CPLListGet((theClass)->subtypes, (rank))) -#define CountTypeFields_GCIO(theClass) CPLListCount((theClass)->fields) -#define GetTypeField_GCIO(theClass, rank) \ - (GCField *)CPLListGetData(CPLListGet((theClass)->fields, (rank))) - -#define GetSubTypeType_GCIO(theSubType) (theSubType)->_type -#define SetSubTypeType_GCIO(theSubType, v) (theSubType)->_type = (v) -#define GetSubTypeName_GCIO(theSubType) (theSubType)->name -#define SetSubTypeName_GCIO(theSubType, v) (theSubType)->name = (v) -#define GetSubTypeID_GCIO(theSubType) (theSubType)->id -#define SetSubTypeID_GCIO(theSubType, v) (theSubType)->id = (v) -#define GetSubTypeKind_GCIO(theSubType) (theSubType)->knd -#define SetSubTypeKind_GCIO(theSubType, v) (theSubType)->knd = (v) -#define GetSubTypeDim_GCIO(theSubType) (theSubType)->sys -#define SetSubTypeDim_GCIO(theSubType, v) (theSubType)->sys = (v) -#define GetSubTypeFields_GCIO(theSubType) (theSubType)->fields -#define SetSubTypeFields_GCIO(theSubType, v) (theSubType)->fields = (v) -#define CountSubTypeFields_GCIO(theSubType) CPLListCount((theSubType)->fields) -#define GetSubTypeField_GCIO(theSubType, rank) \ - (GCField *)CPLListGetData(CPLListGet((theSubType)->fields, (rank))) -#define GetSubTypeNbFields_GCIO(theSubType) (theSubType)->_nbf -#define SetSubTypeNbFields_GCIO(theSubType, v) (theSubType)->_nbf = (v) -#define GetSubTypeNbFeatures_GCIO(theSubType) (theSubType)->_nFeatures -#define SetSubTypeNbFeatures_GCIO(theSubType, v) (theSubType)->_nFeatures = (v) -#define GetSubTypeBOF_GCIO(theSubType) (theSubType)->_foff -#define SetSubTypeBOF_GCIO(theSubType, v) (theSubType)->_foff = (v) -#define GetSubTypeBOFLinenum_GCIO(theSubType) (theSubType)->_flin -#define SetSubTypeBOFLinenum_GCIO(theSubType, v) (theSubType)->_flin = (v) -#define GetSubTypeExtent_GCIO(theSubType) (theSubType)->frame -#define SetSubTypeExtent_GCIO(theSubType, v) (theSubType)->frame = (v) -#define GetSubTypeGCHandle_GCIO(theSubType) (theSubType)->_h -#define SetSubTypeGCHandle_GCIO(theSubType, v) (theSubType)->_h = (v) -#define GetSubTypeFeatureDefn_GCIO(theSubType) (theSubType)->_poFeaDefn -#define SetSubTypeFeatureDefn_GCIO(theSubType, v) (theSubType)->_poFeaDefn = (v) -#define IsSubTypeHeaderWritten_GCIO(theSubType) (theSubType)->_hdrW -#define SetSubTypeHeaderWritten_GCIO(theSubType, v) (theSubType)->_hdrW = (v) - -#define GetFieldName_GCIO(theField) (theField)->name -#define SetFieldName_GCIO(theField, v) (theField)->name = (v) -#define GetFieldID_GCIO(theField) (theField)->id -#define SetFieldID_GCIO(theField, v) (theField)->id = (v) -#define GetFieldKind_GCIO(theField) (theField)->knd -#define SetFieldKind_GCIO(theField, v) (theField)->knd = (v) -#define GetFieldExtra_GCIO(theField) (theField)->extra -#define SetFieldExtra_GCIO(theField, v) (theField)->extra = (v) -#define GetFieldList_GCIO(theField) (theField)->enums -#define SetFieldList_GCIO(theField, v) (theField)->enums = (v) -#define IsPrivateField_GCIO(theField) (*(GetFieldName_GCIO(theField)) == '@') - -#define GetExtentULAbscissa_GCIO(theExtent) (theExtent)->XUL -#define GetExtentULOrdinate_GCIO(theExtent) (theExtent)->YUL -#define SetExtentULAbscissa_GCIO(theExtent, v) \ - (theExtent)->XUL = (v) < (theExtent)->XUL ? (v) : (theExtent)->XUL -#define SetExtentULOrdinate_GCIO(theExtent, v) \ - (theExtent)->YUL = (v) > (theExtent)->YUL ? (v) : (theExtent)->YUL -#define GetExtentLRAbscissa_GCIO(theExtent) (theExtent)->XLR -#define GetExtentLROrdinate_GCIO(theExtent) (theExtent)->YLR -#define SetExtentLRAbscissa_GCIO(theExtent, v) \ - (theExtent)->XLR = (v) > (theExtent)->XLR ? (v) : (theExtent)->XLR -#define SetExtentLROrdinate_GCIO(theExtent, v) \ - (theExtent)->YLR = (v) < (theExtent)->YLR ? (v) : (theExtent)->YLR - -/* OGREnvelope C API : */ -#define InitOGREnvelope_GCIO(poEvlp) \ - if (poEvlp != NULL) \ - { \ - (poEvlp)->MinX = (poEvlp)->MinY = HUGE_VAL; \ - (poEvlp)->MaxX = (poEvlp)->MaxY = -HUGE_VAL; \ - } - -#define MergeOGREnvelope_GCIO(poEvlp, x, y) \ - if (poEvlp != NULL) \ - { \ - if ((x) < (poEvlp)->MinX) \ - (poEvlp)->MinX = (x); \ - if ((x) > (poEvlp)->MaxX) \ - (poEvlp)->MaxX = (x); \ - if ((y) < (poEvlp)->MinY) \ - (poEvlp)->MinY = (y); \ - if ((y) > (poEvlp)->MaxY) \ - (poEvlp)->MaxY = (y); \ - } - -#ifdef __cplusplus -} -#endif - -#endif /* ndef GEOCONCEPT_H_INCLUDED */ diff --git a/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c b/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c deleted file mode 100644 index d05c3494c494..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c +++ /dev/null @@ -1,1213 +0,0 @@ -/********************************************************************** - * $Id: geoconcept_syscoord.c$ - * - * Name: geoconcept_syscoord.c - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements translation between Geoconcept SysCoord - * and OGRSpatialRef format - * Language: C - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008-2010, Even Rouault - * - * SPDX-License-Identifier: MIT - **********************************************************************/ - -#include "geoconcept_syscoord.h" -#include "cpl_string.h" - -/* -------------------------------------------------------------------- */ -/* GCSRS globals */ -/* -------------------------------------------------------------------- */ - -/* - * The following information came from GEO CONCEPT PROJECTION files, - * aka GCP files. - * A lot of information has been added to these GCP. There are mostly - * noticed as FIXME in the source. - */ - -static const GCSysCoord gk_asSysCoordList[] = - /* - * pszSysCoordName, pszUnit, dfPM, dfLambda0, dfPhi0, dfk0, dfX0, dfY0, - * dfPhi1, dfPhi2, nDatumID, nProjID, coordSystemID, timeZoneValue - * - * #12, #14, #15, #17 : parameters listed below are "generic" ... - * - * Geoconcept uses cos(lat_ts) as scale factor, but - * cos(lat_ts)==cos(-lat_ts) : I then set dfPhi1 with lat_ts - */ - {{"Lambert 2 extended", NULL, 2.337229166667, 0.000000000, 46.80000000, - 0.99987742000, 600000.000, 2200000.000, 0.0, 0.0, 13, 2, 1, -1}, - {"Lambert 1", NULL, 2.337229166667, 0.000000000, 49.50000000, - 0.99987734000, 600000.000, 200000.000, 0.0, 0.0, 13, 2, 2, -1}, - {"Lambert 2", NULL, 2.337229166667, 0.000000000, 46.80000000, - 0.99987742000, 600000.000, 200000.000, 0.0, 0.0, 13, 2, 3, -1}, - {"Lambert 3", NULL, 2.337229166667, 0.000000000, 44.10000000, - 0.99987750000, 600000.000, 200000.000, 0.0, 0.0, 13, 2, 4, -1}, - {"Lambert 4", NULL, 2.337229166667, 0.000000000, 42.16500000, - 0.99994471000, 234.358, 185861.369, 0.0, 0.0, 13, 2, 5, -1}, - {"Bonne NTF", NULL, 2.337222222222, 0.000000000, 48.86000000, - 1.00000000000, 0.000, 0.000, 0.0, 0.0, 1, 3, 11, -1}, - {"UTM Nord - ED50", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 14, 1, 12, 0}, - {"Plate carr" - "\xe9" - "e", - NULL, 0.000000000000, 0.000000000, 0.00000000, 0.00000000000, 0.000, - 0.000, 0.0, 0.0, 11, 4, 13, -1}, - {"MGRS (Military UTM)", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 0.000, 0.000, 0.0, 0.0, 4, 11, 14, -1}, - {"UTM Sud - WGS84", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 4, 1, 15, 0}, - {"National GB projection", NULL, 0.000000000000, -2.000000000, 49.00000000, - 0.99960127170, 400000.000, -100000.000, 0.0, 0.0, 12, 12, 16, -1}, - {"UTM Nord - WGS84", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 4, 1, 17, 0}, - {"UTM Nord - WGS84", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 9990, 1, 17, 0}, - {"Lambert 2 " - "\xe9" - "tendu - sans grille", - NULL, 2.337229166667, 0.000000000, 46.80000000, 0.99987742000, 600000.000, - 2200000.000, 0.0, 0.0, 1, 2, 91, -1}, - {"Lambert 1 - sans grille", NULL, 2.337229166667, 0.000000000, 49.50000000, - 0.99987734000, 600000.000, 200000.000, 0.0, 0.0, 1, 2, 92, -1}, - {"Lambert 2 - sans grille", NULL, 2.337229166667, 0.000000000, 46.80000000, - 0.99987742000, 600000.000, 200000.000, 0.0, 0.0, 1, 2, 93, -1}, - {"Lambert 3 - sans grille", NULL, 2.337229166667, 0.000000000, 44.10000000, - 0.99987750000, 600000.000, 200000.000, 0.0, 0.0, 1, 2, 94, -1}, - {"Lambert 4 - sans grille", NULL, 2.337229166667, 0.000000000, 42.16500000, - 0.99994471000, 234.358, 185861.369, 0.0, 0.0, 1, 2, 95, -1}, - {"(Long/Lat) NTF", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 1, 0, 100, -1}, - {"(Long/Lat) WGS84", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 4, 0, 101, -1}, - {"(Long/Lat) ED50", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 14, 0, 102, -1}, - {"(Long/Lat) Australian 1984", "d", 0.000000000000, 0.000000000, - 0.00000000, 0.00000000000, 0.000, 0.000, 0.0, 0.0, 7, 0, 103, -1}, - {"(Long/Lat) Airy", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 12, 0, 104, -1}, - {"(Long/Lat) NTF Paris (gr)", "gr", 2.337229166667, 0.000000000, - 0.00000000, 0.00000000000, 0.000, 0.000, 0.0, 0.0, 1, 0, 105, -1}, - {"(Long/Lat) WGS 72", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 3, 0, 107, -1}, - {"Geoportail MILLER", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 4, 24, 222, -1}, - {"IGN-RRAFGUADU20", NULL, 0.000000000000, -63.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 9984, 1, 501, - -1}, /* FIXME does not exist in IGNF, use IGN-UTM20W84GUAD instead */ - {"IGN-RRAFMARTU20", NULL, 0.000000000000, -63.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 9984, 1, 502, - -1}, /* FIXME does not exist in IGNF, use IGN-UTM20W84MART instead, never - reached cause identical to 501:-1 */ - {"IGN-RGM04UTM38S", NULL, 0.000000000000, 45.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 503, - -1}, /* FIXME 5030 datum changed into 9984 */ - {"IGN-RGR92UTM40S", NULL, 0.000000000000, 57.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 504, -1}, - {"IGN-UTM22RGFG95", NULL, 0.000000000000, -51.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 9984, 1, 505, -1}, - {"IGN-UTM01SWG84", NULL, 0.000000000000, -177.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 506, - -1}, /* never reached cause identical to 15:1 */ - {"IGN-RGSPM06U21", NULL, 0.000000000000, -57.000000000, 0.00000000, - 0.99960000000, 500000.000, 0.000, 0.0, 0.0, 9984, 1, 507, -1}, - {"IGN-RGPFUTM5S", NULL, 0.000000000000, -153.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 508, -1}, - {"IGN-RGPFUTM6S", NULL, 0.000000000000, -147.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 509, -1}, - {"IGN-RGPFUTM7S", NULL, 0.000000000000, -141.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 510, -1}, - {"IGN-CROZ63UTM39S", NULL, 0.000000000000, 51.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9983, 1, 511, -1}, - {"IGN-WGS84UTM1S", NULL, 0.000000000000, -177.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 4, 1, 512, -1}, - {"IGN-RGNCUTM57S", NULL, 0.000000000000, 159.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 513, -1}, - {"IGN-RGNCUTM58S", NULL, 0.000000000000, 165.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 514, -1}, - {"IGN-RGNCUTM59S", NULL, 0.000000000000, 171.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9984, 1, 515, -1}, - {"IGN-KERG62UTM42S", NULL, 0.000000000000, 69.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 9988, 1, 516, -1}, - {"IGN-REUN47GAUSSL", NULL, 0.000000000000, 55.533333333, -21.11666667, - 1.00000000000, 160000.000, 50000.000, 0.0, 0.0, 2, 19, 520, -1}, - {"Lambert 1 Carto", NULL, 2.337229166667, 0.000000000, 49.50000000, - 0.99987734000, 600000.000, 1200000.000, 0.0, 0.0, 13, 2, 1002, -1}, - {"Lambert 2 Carto", NULL, 2.337229166667, 0.000000000, 46.80000000, - 0.99987742000, 600000.000, 2200000.000, 0.0, 0.0, 13, 2, 1003, - -1}, /* never reached cause identical to 1:-1 */ - {"Lambert 3 Carto", NULL, 2.337229166667, 0.000000000, 44.10000000, - 0.99987750000, 600000.000, 3200000.000, 0.0, 0.0, 13, 2, 1004, -1}, - {"Lambert 4 Carto", NULL, 2.337229166667, 0.000000000, 42.16500000, - 0.99994471000, 234.358, 4185861.369, 0.0, 0.0, 13, 2, 1005, -1}, - {"Lambert 93", NULL, 0.000000000000, 3.000000000, 46.50000000, - 0.00000000000, 700000.000, 6600000.000, 44.0, 49.0, 9984, 18, 1006, -1}, - {"IGN-RGNCLAM", NULL, 0.000000000000, 166.000000000, -21.30000000, - 0.00000000000, 400000.000, 300000.000, -20.4, -22.2, 9984, 18, 1007, - -1}, /* Added in GCP */ - {"Lambert 1 Carto - sans grille", NULL, 2.337229166667, 0.000000000, - 49.50000000, 0.99987734000, 600000.000, 1200000.000, 0.0, 0.0, 1, 2, 1092, - -1}, - {"Lambert 2 Carto - sans grille", NULL, 2.337229166667, 0.000000000, - 46.80000000, 0.99987742000, 600000.000, 2200000.000, 0.0, 0.0, 1, 2, 1093, - -1}, - {"Lambert 3 Carto - sans grille", NULL, 2.337229166667, 0.000000000, - 44.10000000, 0.99987750000, 600000.000, 3200000.000, 0.0, 0.0, 1, 2, 1094, - -1}, - {"Lambert 4 Carto - sans grille", NULL, 2.337229166667, 0.000000000, - 42.16500000, 0.99994471000, 234.358, 185861.369, 0.0, 0.0, 1, 2, 1095, - -1}, - {"Suisse", NULL, 0.000000000000, 7.439583333, 46.95240556, 1.00000000000, - 600000.000, 200000.000, 0.0, 0.0, 2, 25, 1556, -1}, - {"Geoportail France", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.68835457569, 0.000, 0.000, 46.5, 0.0, 9984, 26, 2012, -1}, - {"Geoportail Antilles", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.96592582629, 0.000, 0.000, 15.0, 0.0, 9984, 26, 2016, -1}, - {"Geoportail Guyane", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99756405026, 0.000, 0.000, 4.0, 0.0, 9984, 26, 2017, -1}, - {"Geoportail Reunion", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.93358042649, 0.000, 0.000, -21.0, 0.0, 9984, 26, 2018, -1}, - {"Geoportail Mayotte", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.97814760073, 0.000, 0.000, -12.0, 0.0, 9984, 26, 2019, -1}, - {"Geoportail ST Pierre et Miquelon", NULL, 0.000000000000, 0.000000000, - 0.00000000, 0.68199836006, 0.000, 0.000, 47.0, 0.0, 9984, 26, 2020, -1}, - {"Geoportail Nouvelle Caledonie", NULL, 0.000000000000, 0.000000000, - 0.00000000, 0.92718385456, 0.000, 0.000, -22.0, 0.0, 9984, 26, 2021, -1}, - {"Geoportail Wallis", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.97029572627, 0.000, 0.000, -14.0, 0.0, 9984, 26, 2022, -1}, - {"Geoportail Polynesie", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.96592582628, 0.000, 0.000, -15.0, 0.0, 9984, 26, 2023, -1}, - {"Mercator sur sph" - "\xe8" - "re WGS84", - NULL, 0.000000000000, 0.000000000, 0.00000000, 1.00000000000, 0.000, - 0.000, 0.0, 0.0, 2015, 21, 2027, -1}, - {"(Long/Lat) RGF 93", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 13, 0, 2028, -1}, - {"(Long/Lat) ITRS-89", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 2028, -1}, - {"Geoportail Crozet", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.69465837046, 0.000, 0.000, -46.0, 0.0, 9984, 26, 2040, - -1}, /* FIXME : wrong scale factor was 0.69088241108 */ - {"Geoportail Kerguelen", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.64944804833, 0.000, 0.000, -49.5, 0.0, 9984, 26, 2042, - -1}, /* FIXME : wrong scale factor was 0.67815966987 */ - {"Lambert CC 42", NULL, 0.000000000000, 3.000000000, 42.00000000, - 0.00000000000, 1700000.000, 1200000.000, 41.2, 42.8, 9984, 18, 2501, -1}, - {"Lambert CC 43", NULL, 0.000000000000, 3.000000000, 43.00000000, - 0.00000000000, 1700000.000, 2200000.000, 42.2, 43.8, 9984, 18, 2502, -1}, - {"Lambert CC 44", NULL, 0.000000000000, 3.000000000, 44.00000000, - 0.00000000000, 1700000.000, 3200000.000, 43.2, 44.8, 9984, 18, 2503, -1}, - {"Lambert CC 45", NULL, 0.000000000000, 3.000000000, 45.00000000, - 0.00000000000, 1700000.000, 4200000.000, 44.2, 45.8, 9984, 18, 2504, -1}, - {"Lambert CC 46", NULL, 0.000000000000, 3.000000000, 46.00000000, - 0.00000000000, 1700000.000, 5200000.000, 45.2, 46.8, 9984, 18, 2505, -1}, - {"Lambert CC 47", NULL, 0.000000000000, 3.000000000, 47.00000000, - 0.00000000000, 1700000.000, 6200000.000, 46.2, 47.8, 9984, 18, 2506, -1}, - {"Lambert CC 48", NULL, 0.000000000000, 3.000000000, 48.00000000, - 0.00000000000, 1700000.000, 7200000.000, 47.2, 48.8, 9984, 18, 2507, -1}, - {"Lambert CC 49", NULL, 0.000000000000, 3.000000000, 49.00000000, - 0.00000000000, 1700000.000, 8200000.000, 48.2, 49.8, 9984, 18, 2508, -1}, - {"Lambert CC 50", NULL, 0.000000000000, 3.000000000, 50.00000000, - 0.00000000000, 1700000.000, 9200000.000, 49.2, 50.8, 9984, 18, 2509, -1}, - {"(Long/Lat) IGN-RGM04GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10001, -1}, - {"(Long/Lat) IGN-RGFG95GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10002, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) IGN-WGS84RRAFGEO", "d", 0.000000000000, 0.000000000, - 0.00000000, 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10003, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) IGN-RGR92GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10004, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) IGN-WGS84G", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 4, 0, 10005, -1}, - {"(Long/Lat) CROZ63GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 4, 0, 10006, -1}, - {"(Long/Lat) RGSPM06GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10007, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) RGPFGEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10008, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) RGNCGEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9984, 0, 10009, - -1}, /* never reached, identical to 10001:-1 */ - {"(Long/Lat) KER62GEO", "d", 0.000000000000, 0.000000000, 0.00000000, - 0.00000000000, 0.000, 0.000, 0.0, 0.0, 9988, 0, 10010, -1}, - {"UTM Sud - ED50", NULL, 0.000000000000, 0.000000000, 0.00000000, - 0.99960000000, 500000.000, 10000000.000, 0.0, 0.0, 14, 1, 99912, - 0}, /* FIXME allow retrieving 12:0 - See _findSysCoord_GCSRS() */ - {NULL, NULL, 0.000000000000, 0.000000000, 0.00000000, 0.00000000000, 0.000, - 0.000, 0.0, 0.0, -1, -1, -1, -1}}; - -static const GCProjectionInfo gk_asProjList[] = - /* - * pszProjName, nSphere, nProjID - */ - {{"Geographic shift", 0, 0}, - {"UTM", 0, 1}, - {"Lambert Conform Conic", 0, 2}, - {"Bonne", 0, 3}, - {"Plate carr" - "\xe9" - "e", - 0, 4}, - {"MGRS (Military UTM)", 0, 11}, - {"Transversal Mercator", 0, 12}, - {"Lambert secant", 0, 18}, - {"Gauss Laborde", 1, 19}, - {"Polyconic", 0, 20}, - {"Direct Mercator", 0, 21}, - {"Stereographic oblic", 1, 22}, - {"Miller", 0, 24}, - {"Mercator oblic", 1, 25}, - {"Equi rectangular", 1, 26}, - - {NULL, 0, -1}}; - -static const GCDatumInfo gk_asDatumList[] = - /* - * pszDatumName, dfShiftX, dfShiftY, dfShiftZ, dfRotX, dfRotY, dfRotZ, - * dfScaleFactor, dfFA, dfFlattening, nEllipsoidID, nDatumID - */ - /* - * Wrong dx, dy, dz : - * IGN-RGM04GEO, was -217, -216, 67 - * IGN-RGFG95GEO, was -2, -2, 2 - * IGN-RGSPM06GEO, was -125.593, 143.763, -194.558 - * - * #1 and #13 are identical - * #8, #11, #2015 are spherical views of #4 - * #5030, #5031 and #5032 are identical - * FIXME : #5030, #5031, #5032 are ITRS89 compliant, so "compatible" with - * #4, better use #9999 as ellipsoid - * FIXME : #9999 to #9986 added - */ - {{"NTF (Clarke 1880)", -168.0000, -60.0000, 320.0000, 0.00000, 0.00000, - 0.00000, 0.0, -112.200, -54.7388e-6, 3, 1}, - {"ED50 France (International 1909)", -84.0000, -97.0000, -117.0000, - 0.00000, 0.00000, 0.00000, 0.0, -251.000, -14.1927e-6, 5, 2}, - {"WGS 72", 0.0000, 12.0000, 6.0000, 0.00000, 0.00000, 0.00000, 0.0, 2.000, - 0.0312e-6, 6, 3}, - {"WGS_1984", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, 0.000, - 0.0, 9999, 4}, - {"ED 79", -83.0000, -95.0000, -116.0000, 0.00000, 0.00000, 0.00000, 0.0, - -251.000, -14.1927e-6, 5, 5}, - {"Australian Geodetic 1966", -133.0000, -48.0000, 148.0000, 0.00000, - 0.00000, 0.00000, 0.0, -23.000, -0.0081e-6, 7, 6}, - {"Australian Geodetic 1984", -134.0000, -48.0000, 149.0000, 0.00000, - 0.00000, 0.00000, 0.0, -23.000, -0.0081e-6, 7, 7}, - {"Sphere", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, 0.000, - 0.0, 1, 8}, - {"Sphere DCW", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, - 0.000, 0.0, 1, 11}, - {"Airy", 375.0000, -111.0000, 431.0000, 0.00000, 0.00000, 0.00000, 0.0, - 573.604, 11.96002325e-6, 8, 12}, - {"NTF-Grille", -168.0000, -60.0000, 320.0000, 0.00000, 0.00000, 0.00000, - 0.0, -112.200, -54.7388e-6, 3, 13}, - {"ED50 (International 1909)", -87.0000, -98.0000, -121.0000, 0.00000, - 0.00000, 0.00000, 0.0, -251.000, -14.1927e-6, 5, 14}, - {"WGS 84 sur sphere", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, - 0.0, 0.000, 0.0, 1, 2015}, - {"IGN-RGM04GEO", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, - 0.000, 0.0, 4, 5030}, - {"IGN-RGFG95GEO", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, - 0.000, 0.0, 4, 5031}, - {"IGN-RGSPM06GEO", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, - 0.000, 0.0, 4, 5032}, - {"IGN-WALL78", 253.0000, -133.0000, -127.0000, 0.00000, 0.00000, 0.00000, - 0.0, -251.000, -14.1927e-6, 5, 9999}, /* FIXME */ - {"IGN-TAHA", 72.4380, 345.9180, 79.4860, -1.60450, -0.88230, -0.55650, - 1.3746e-6, -251.000, -14.1927e-6, 5, 9998}, /* FIXME */ - {"IGN-MOOREA87", 215.9820, 149.5930, 176.2290, 3.26240, 1.69200, 1.15710, - 10.47730e-6, -251.000, -14.1927e-6, 5, 9997}, /* FIXME */ - {"IGN-TAHI51", 162.0000, 117.0000, 154.0000, 0.00000, 0.00000, 0.00000, - 0.0, -251.000, -14.1927e-6, 5, 9996}, /* FIXME */ - {"IGN-NUKU72", 165.7320, 216.7200, 180.5050, -0.64340, -0.45120, -0.07910, - 7.42040e-6, -251.000, -14.1927e-6, 5, 9995}, /* FIXME */ - {"IGN-IGN63", 410.7210, 55.0490, 80.7460, -2.57790, -2.35140, -0.66640, - 17.33110e-6, -251.000, -14.1927e-6, 5, 9994}, /* FIXME */ - {"IGN-MART38", 126.9260, 547.9390, 130.4090, -2.78670, 5.16124, -0.85844, - 13.82265e-6, -251.000, -14.1927e-6, 5, 9993}, /* FIXME */ - {"IGN-GUAD48", -472.2900, -5.6300, -304.1200, 0.43620, -0.83740, 0.25630, - 1.89840e-6, -251.000, -14.1927e-6, 5, 9992}, /* FIXME */ - {"IGN-GUADFM49", 136.5960, 248.1480, -429.7890, 0.00000, 0.00000, 0.00000, - 0.0, -251.000, -14.1927e-6, 5, 9991}, /* FIXME */ - {"IGN-STPM50", -95.5930, 573.7630, 173.4420, -0.96020, 1.25100, -1.39180, - 42.62650e-6, -69.400, -37.2957e-6, 2, 9990}, /* FIXME */ - {"IGN-CSG67", -193.0660, 236.9930, 105.4470, 0.48140, -0.80740, 0.12760, - 1.56490e-6, -251.000, -14.1927e-6, 5, 9989}, /* FIXME */ - {"IGN-KERG62", 145.0000, -187.0000, 103.0000, 0.00000, 0.00000, 0.00000, - 0.0, -251.000, -14.1927e-6, 5, 9988}, /* FIXME */ - {"IGN-REUN47", 789.5240, -626.4860, -89.9040, 0.60060, 76.79460, -10.57880, - -32.32410e-6, -251.000, -14.1927e-6, 5, 9987}, /* FIXME */ - {"IGN-MAYO50", -599.9280, -275.5520, -195.6650, 0.08350, 0.47150, -0.06020, - -49.28140e-6, -251.000, -14.1927e-6, 5, 9986}, /* FIXME */ - {"IGN-TAHI79", 221.5250, 152.9480, 176.7680, 2.38470, 1.38960, 0.87700, - 11.47410e-6, -251.000, -14.1927e-6, 5, 9985}, /* FIXME */ - {"ITRS-89", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, 0.000, - 0.0, 4, 9984}, - {"IGN-CROZ63", 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, - -251.000, -14.1927e-6, 5, - 9983}, /* FIXME added cause the Bursa-Wolf parameters are not known */ - - {NULL, 0.0000, 0.0000, 0.0000, 0.00000, 0.00000, 0.00000, 0.0, 0.000, 0.0, - -1, -1}}; - -static const GCSpheroidInfo gk_asSpheroidList[] = - /* - * pszSpheroidName, dfA, dfE, nEllipsoidID - * - * cause Geoconcept assimilates WGS84 and GRS80, WGS84 is added to the list - */ - {{"Sphere", 6378137.0000, 0.00000000000000, 1}, - {"Clarke 1866", 6378206.4000, 0.08227185423947, - 2}, /* Wrong, semi-major was 6378249.4000 */ - {"Clarke 1880", 6378249.2000, 0.08248325676300, - 3}, /* Wrong, eccentricity was 0.082483256945 */ - {"GRS 80", 6378137.0000, 0.08181919104300, - 4}, /* Wrong, eccentricity was 0.081819191060 */ - {"International 1909", 6378388.0000, 0.08199188997900, 5}, - {"WGS 72", 6378135.0000, 0.08181881201777, 6}, - {"Australian National", 6378160.0000, 0.08182017998700, 7}, - {"Airy", 6377563.3960, 0.08167337387420, 8}, - {"WGS 84", 6378137.0000, 0.08181919084262, 9999}, - - {NULL, 0, 0, -1}}; - -/* -------------------------------------------------------------------- */ -/* GCSRS API Prototypes */ -/* -------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------- */ -static int GCSRSAPI_CALL _areCompatibleSpheroids_GCSRS(int id1, int id2) -{ - if (id1 == id2) - return TRUE; - - switch (id1) - { - case 4: - case 9999: - switch (id2) - { - case 4: - case 9999: - return TRUE; - default: - break; - } - break; - default: - break; - } - - return FALSE; -} /* _areCompatibleSpheroids_GCSRS */ - -/* -------------------------------------------------------------------- */ -static int GCSRSAPI_CALL _areCompatibleDatums_GCSRS(int id1, int id2) -{ - if (id1 == id2) - return TRUE; - - switch (id1) - { - case 1: /* NTF */ - case 13: - switch (id2) - { - case 1: - case 13: - return TRUE; - default: - break; - } - break; - case 2: /* ED50 */ - case 14: - case 9983: - case 9985: - case 9986: - case 9987: - case 9989: - case 9991: - case 9992: - case 9993: - case 9994: - case 9995: - case 9997: - case 9998: - case 9999: - switch (id2) - { - case 2: - case 14: - case 9983: - case 9985: - case 9986: - case 9987: - case 9989: - case 9991: - case 9992: - case 9993: - case 9994: - case 9995: - case 9997: - case 9998: - case 9999: - return TRUE; - default: - break; - } - break; - case 4: /* WGS84 - ITRS89 */ - case 8: - case 11: - case 2015: - case 5030: - case 5031: - case 5032: - case 9984: - switch (id2) - { - case 4: - case 8: - case 11: - case 2015: - case 5030: - case 5031: - case 5032: - case 9984: - return TRUE; - default: - break; - } - break; - default: - break; - } - - return FALSE; -} /* _areCompatibleDatums_GCSRS */ - -#define CPLDebugSpheroid_GCSRS(e) \ - CPLDebug("GEOCONCEPT", "SemiMajor:%.4f;Eccentricity:%.10f;", \ - GetInfoSpheroidSemiMajor_GCSRS(e), \ - GetInfoSpheroidExcentricity_GCSRS(e)); - -/* -------------------------------------------------------------------- */ -static const GCSpheroidInfo GCSRSAPI_CALL1(*) - _findSpheroid_GCSRS(double a, double rf) -{ - int iSpheroid, iResol = 0, nResol = 2; - const GCSpheroidInfo *ell; - double e, p[] = {1e-10, 1e-8}; - - /* f = 1 - sqrt(1 - e^2) */ - e = (rf == 0.0) ? 0.0 : 1.0 / rf; - e = sqrt(e * (2.0 - e)); -ell_relax: - for (iSpheroid = 0, ell = &(gk_asSpheroidList[0]); - GetInfoSpheroidID_GCSRS(ell) != -1; - iSpheroid++, ell = &(gk_asSpheroidList[iSpheroid])) - { - if (fabs(GetInfoSpheroidSemiMajor_GCSRS(ell) - a) > 1e-4) - continue; - if (fabs(GetInfoSpheroidExcentricity_GCSRS(ell) - e) > p[iResol]) - continue; - break; - } - if (GetInfoSpheroidID_GCSRS(ell) == -1 && iResol != nResol - 1) - { - iResol++; - goto ell_relax; - } - - return ell; -} /* _findSpheroid_GCSRS */ - -#define CPLDebugDatum_GCSRS(d) \ - CPLDebug("GEOCONCEPT", \ - "ID:%d;ShiftX:%.4f;ShiftY:%.4f;ShiftZ:%.4f;DiffA:%.4f;" \ - "DiffFlattening:%.7f;", \ - GetInfoDatumID_GCSRS((d)), GetInfoDatumShiftX_GCSRS((d)), \ - GetInfoDatumShiftY_GCSRS((d)), GetInfoDatumShiftZ_GCSRS((d)), \ - GetInfoDatumDiffA_GCSRS((d)), \ - GetInfoDatumDiffFlattening_GCSRS((d))); - -/* -------------------------------------------------------------------- */ -static const GCDatumInfo GCSRSAPI_CALL1(*) - _findDatum_GCSRS(double dx, double dy, double dz, double a, double f) -{ - int iDatum, bRelax = FALSE; - const GCDatumInfo *datum; - -datum_relax: - for (iDatum = 0, datum = &(gk_asDatumList[0]); - GetInfoDatumID_GCSRS(datum) != -1; - iDatum++, datum = &(gk_asDatumList[iDatum])) - { - if (!bRelax) - { - if (fabs(GetInfoDatumShiftX_GCSRS(datum) - dx) > 1e-4) - continue; - if (fabs(GetInfoDatumShiftY_GCSRS(datum) - dy) > 1e-4) - continue; - if (fabs(GetInfoDatumShiftZ_GCSRS(datum) - dz) > 1e-4) - continue; - } - if (fabs(GetInfoDatumDiffA_GCSRS(datum) - (6378137.0000 - a)) > 1e-4) - continue; - if (fabs(GetInfoDatumDiffFlattening_GCSRS(datum) - - (0.003352779565406696648 - f)) > 1e-7) - continue; - break; - } - if (GetInfoDatumID_GCSRS(datum) == -1 && !bRelax) - { - /* - * FIXME : when both nadgrids and towgs84 are defined, bursa-wolf - * parameters are lost ! if the projection and the ellipsoid are known, - * one can retrieve the datum Try relaxed search ... - */ - bRelax = TRUE; - goto datum_relax; - } - - return datum; -} /* _findDatum_GCSRS */ - -/* -------------------------------------------------------------------- */ -static const GCProjectionInfo GCSRSAPI_CALL1(*) - _findProjection_GCSRS(const char *p, double lat_ts) -{ - int iProj; - const GCProjectionInfo *proj; - - for (iProj = 0, proj = &(gk_asProjList[0]); GetInfoProjID_GCSRS(proj) != -1; - iProj++, proj = &(gk_asProjList[iProj])) - { - if (iProj == 0 && p == NULL) - break; - if (iProj == 1 && (EQUAL(p, SRS_PT_TRANSVERSE_MERCATOR) || - EQUAL(p, SRS_PT_TRANSVERSE_MERCATOR_SOUTH_ORIENTED))) - break; - if (iProj == 2 && EQUAL(p, SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP)) - break; - if (iProj == 3 && EQUAL(p, SRS_PT_BONNE)) - break; - if (iProj == 4 && EQUAL(p, SRS_PT_EQUIRECTANGULAR) && lat_ts == 0.0) - break; - /* FIXME : iProj==6 ? */ - if (iProj == 7 && - (EQUAL(p, SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP) || - EQUAL(p, SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP_BELGIUM))) - break; - if (iProj == 8 && EQUAL(p, SRS_PT_GAUSSSCHREIBERTMERCATOR)) - break; - if (iProj == 9 && EQUAL(p, SRS_PT_POLYCONIC)) - break; - /* FIXME - if( iProj==10 && - ( EQUAL(p,SRS_PT_MERCATOR_1SP) || - EQUAL(p,SRS_PT_MERCATOR_2SP) ) ) - break; - */ - if (iProj == 11 && (EQUAL(p, SRS_PT_OBLIQUE_STEREOGRAPHIC) || - EQUAL(p, SRS_PT_POLAR_STEREOGRAPHIC))) - break; - if (iProj == 12 && EQUAL(p, SRS_PT_MILLER_CYLINDRICAL)) - break; - /* FIXME - if( iProj==13 && - ( EQUAL(p,SRS_PT_HOTINE_OBLIQUE_MERCATOR) || - EQUAL(p,SRS_PT_HOTINE_OBLIQUE_MERCATOR_TWO_POINT_NATURAL_ORIGIN) - || EQUAL(p,SRS_PT_LABORDE_OBLIQUE_MERCATOR) ) ) break; - */ - if (iProj == 14 && EQUAL(p, SRS_PT_EQUIRECTANGULAR) && lat_ts != 0.0) - break; - } - - return proj; -} /* _findProjection_GCSRS */ - -#define CPLDebugSysCoord_GCSRS(m, s) \ - CPLDebug( \ - "GEOCONCEPT", \ - "[%s]ID=%d;Zone=%d;DatumID=%d;ProjID=%d;PrimeMeridian=%.10f;" \ - "CentralMeridian=%.10f;LatitudeOfOrigin=%.10f;StandardParallel1=%." \ - "10f;StandardParallel2=%.10f;ScaleFactor=%.10f;FalseEasting=%.10f;" \ - "FalseNorthing=%.10f;", \ - (m) ? (m) : "", GetSysCoordSystemID_GCSRS((s)), \ - GetSysCoordTimeZone_GCSRS((s)), GetSysCoordDatumID_GCSRS((s)), \ - GetSysCoordProjID_GCSRS((s)), GetSysCoordPrimeMeridian_GCSRS((s)), \ - GetSysCoordCentralMeridian_GCSRS((s)), \ - GetSysCoordLatitudeOfOrigin_GCSRS((s)), \ - GetSysCoordStandardParallel1_GCSRS((s)), \ - GetSysCoordStandardParallel2_GCSRS((s)), \ - GetSysCoordScaleFactor_GCSRS((s)), GetSysCoordFalseEasting_GCSRS((s)), \ - GetSysCoordFalseNorthing_GCSRS((s))); - -/* -------------------------------------------------------------------- */ -static GCSysCoord GCSRSAPI_CALL1(*) _findSysCoord_GCSRS(GCSysCoord *theSysCoord) -{ - int iSysCoord, bestSysCoord = -1; - const GCSysCoord *gcsc; - - if (!theSysCoord) - return NULL; - - SetSysCoordSystemID_GCSRS(theSysCoord, -1); - SetSysCoordTimeZone_GCSRS(theSysCoord, -1); - CPLDebugSysCoord_GCSRS(NULL, theSysCoord); - for (iSysCoord = 0, gcsc = &(gk_asSysCoordList[0]); - GetSysCoordSystemID_GCSRS(gcsc) != -1; - iSysCoord++, gcsc = &(gk_asSysCoordList[iSysCoord])) - { - if (!_areCompatibleDatums_GCSRS(GetSysCoordDatumID_GCSRS(gcsc), - GetSysCoordDatumID_GCSRS(theSysCoord))) - continue; - - if (GetSysCoordProjID_GCSRS(gcsc) != - GetSysCoordProjID_GCSRS(theSysCoord)) - continue; - - if (fabs(GetSysCoordPrimeMeridian_GCSRS(gcsc) - - GetSysCoordPrimeMeridian_GCSRS(theSysCoord)) > 1e-8) - continue; - - if (fabs(GetSysCoordCentralMeridian_GCSRS(gcsc) - - GetSysCoordCentralMeridian_GCSRS(theSysCoord)) > 1e-8) - { - /* UTM family: central meridian is the 6* zone - 183 (in degrees) */ - if (GetSysCoordProjID_GCSRS(gcsc) == 1 && - /* generic UTM definition */ - GetSysCoordCentralMeridian_GCSRS(gcsc) == 0.0) - { - /* go on */ - } - else - { - continue; - } - } - if (fabs(GetSysCoordLatitudeOfOrigin_GCSRS(gcsc) - - GetSysCoordLatitudeOfOrigin_GCSRS(theSysCoord)) > 1e-8) - continue; - - if (fabs(GetSysCoordStandardParallel1_GCSRS(gcsc) - - GetSysCoordStandardParallel1_GCSRS(theSysCoord)) > 1e-8) - continue; - if (fabs(GetSysCoordStandardParallel2_GCSRS(gcsc) - - GetSysCoordStandardParallel2_GCSRS(theSysCoord)) > 1e-8) - continue; - - if (fabs(GetSysCoordScaleFactor_GCSRS(gcsc) - - GetSysCoordScaleFactor_GCSRS(theSysCoord)) > 1e-8) - continue; - - if (fabs(GetSysCoordFalseEasting_GCSRS(gcsc) - - GetSysCoordFalseEasting_GCSRS(theSysCoord)) > 1e-4) - continue; - if (fabs(GetSysCoordFalseNorthing_GCSRS(gcsc) - - GetSysCoordFalseNorthing_GCSRS(theSysCoord)) > 1e-4) - continue; - - /* Found a candidate : */ - if (bestSysCoord == -1) - { - bestSysCoord = iSysCoord; - } - else - { - switch (GetSysCoordProjID_GCSRS(gcsc)) - { - case 0: /* long/lat */ - if (GetSysCoordDatumID_GCSRS(gcsc) == - GetSysCoordDatumID_GCSRS(theSysCoord) && - GetSysCoordDatumID_GCSRS( - &(gk_asSysCoordList[bestSysCoord])) != - GetSysCoordDatumID_GCSRS( - theSysCoord)) /* exact match */ - { - bestSysCoord = iSysCoord; - } - break; - case 1: /* UTM family: central meridian is the 6* zone - 183 (in - degrees) */ - if (GetSysCoordCentralMeridian_GCSRS(gcsc) != 0.0 && - GetSysCoordDatumID_GCSRS(gcsc) == - GetSysCoordDatumID_GCSRS(theSysCoord) && - GetSysCoordDatumID_GCSRS( - &(gk_asSysCoordList[bestSysCoord])) != - GetSysCoordDatumID_GCSRS( - theSysCoord)) /* exact match */ - { - bestSysCoord = iSysCoord; - } - break; - default: - break; - } - } - } - /* Seems to be the right Geoconcept system: */ - if (bestSysCoord >= 0) - { - gcsc = &(gk_asSysCoordList[bestSysCoord]); - switch (GetSysCoordSystemID_GCSRS(gcsc)) - { - case 99912: /* hack */ - SetSysCoordSystemID_GCSRS(theSysCoord, 12); - break; - default: - SetSysCoordSystemID_GCSRS(theSysCoord, - GetSysCoordSystemID_GCSRS(gcsc)); - break; - } - SetSysCoordTimeZone_GCSRS(theSysCoord, GetSysCoordTimeZone_GCSRS(gcsc)); - if (GetSysCoordName_GCSRS(gcsc)) - SetSysCoordName_GCSRS(theSysCoord, GetSysCoordName_GCSRS(gcsc)); - if (GetSysCoordUnit_GCSRS(gcsc)) - SetSysCoordUnit_GCSRS(theSysCoord, GetSysCoordUnit_GCSRS(gcsc)); - } - - return theSysCoord; -} /* _findSysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -static void GCSRSAPI_CALL _InitSysCoord_GCSRS(GCSysCoord *theSysCoord) -{ - SetSysCoordSystemID_GCSRS(theSysCoord, -1); - SetSysCoordTimeZone_GCSRS(theSysCoord, -1); - SetSysCoordName_GCSRS(theSysCoord, NULL); - SetSysCoordUnit_GCSRS(theSysCoord, NULL); - SetSysCoordCentralMeridian_GCSRS(theSysCoord, 0.0); - SetSysCoordLatitudeOfOrigin_GCSRS(theSysCoord, 0.0); - SetSysCoordStandardParallel1_GCSRS(theSysCoord, 0.0); - SetSysCoordStandardParallel2_GCSRS(theSysCoord, 0.0); - SetSysCoordScaleFactor_GCSRS(theSysCoord, 0.0); - SetSysCoordFalseEasting_GCSRS(theSysCoord, 0.0); - SetSysCoordFalseNorthing_GCSRS(theSysCoord, 0.0); - SetSysCoordDatumID_GCSRS(theSysCoord, -1); - SetSysCoordProjID_GCSRS(theSysCoord, -1); - SetSysCoordPrimeMeridian_GCSRS(theSysCoord, 0); -} /* _InitSysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -GCSysCoord GCSRSAPI_CALL1(*) CreateSysCoord_GCSRS(int srsid, int nTimezone) -{ - int iSysCoord; - GCSysCoord *theSysCoord; - const GCSysCoord *gcsc; - - if (!(theSysCoord = VSI_MALLOC_VERBOSE(sizeof(GCSysCoord)))) - { - return NULL; - } - _InitSysCoord_GCSRS(theSysCoord); - if (srsid >= 0) - { - for (iSysCoord = 0, gcsc = &(gk_asSysCoordList[0]); - GetSysCoordSystemID_GCSRS(gcsc) != -1; - iSysCoord++, gcsc = &(gk_asSysCoordList[iSysCoord])) - { - if (srsid == GetSysCoordSystemID_GCSRS(gcsc)) - { - SetSysCoordSystemID_GCSRS(theSysCoord, srsid); - SetSysCoordTimeZone_GCSRS(theSysCoord, nTimezone); - if (GetSysCoordName_GCSRS(gcsc)) - SetSysCoordName_GCSRS(theSysCoord, - GetSysCoordName_GCSRS(gcsc)); - if (GetSysCoordUnit_GCSRS(gcsc)) - SetSysCoordUnit_GCSRS(theSysCoord, - GetSysCoordUnit_GCSRS(gcsc)); - SetSysCoordCentralMeridian_GCSRS( - theSysCoord, GetSysCoordCentralMeridian_GCSRS(gcsc)); - SetSysCoordLatitudeOfOrigin_GCSRS( - theSysCoord, GetSysCoordLatitudeOfOrigin_GCSRS(gcsc)); - SetSysCoordStandardParallel1_GCSRS( - theSysCoord, GetSysCoordStandardParallel1_GCSRS(gcsc)); - SetSysCoordStandardParallel2_GCSRS( - theSysCoord, GetSysCoordStandardParallel2_GCSRS(gcsc)); - SetSysCoordScaleFactor_GCSRS( - theSysCoord, GetSysCoordScaleFactor_GCSRS(gcsc)); - SetSysCoordFalseEasting_GCSRS( - theSysCoord, GetSysCoordFalseEasting_GCSRS(gcsc)); - SetSysCoordFalseNorthing_GCSRS( - theSysCoord, GetSysCoordFalseNorthing_GCSRS(gcsc)); - SetSysCoordDatumID_GCSRS(theSysCoord, - GetSysCoordDatumID_GCSRS(gcsc)); - SetSysCoordProjID_GCSRS(theSysCoord, - GetSysCoordProjID_GCSRS(gcsc)); - break; - } - } - } - - return theSysCoord; -} /* CreateSysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -static void GCSRSAPI_CALL _ReInitSysCoord_GCSRS(GCSysCoord *theSysCoord) -{ - _InitSysCoord_GCSRS(theSysCoord); -} /* _ReInitSysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -void GCSRSAPI_CALL DestroySysCoord_GCSRS(GCSysCoord **theSysCoord) -{ - _ReInitSysCoord_GCSRS(*theSysCoord); - CPLFree(*theSysCoord); - *theSysCoord = NULL; -} /* DestroySysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -GCSysCoord GCSRSAPI_CALL1(*) - OGRSpatialReference2SysCoord_GCSRS(OGRSpatialReferenceH poSR) -{ - char *pszProj4 = NULL; - const GCSpheroidInfo *ell = NULL; - const GCDatumInfo *datum = NULL; - const GCProjectionInfo *gcproj = NULL; - double a, rf, f, p[7] = {0, 0, 0, 0, 0, 0, 0}; - GCSysCoord *syscoord = NULL; - - if (!poSR) - return NULL; - - pszProj4 = NULL; - OSRExportToProj4(poSR, &pszProj4); - if (!pszProj4) - pszProj4 = CPLStrdup(""); - - CPLDebug("GEOCONCEPT", "SRS : %s", pszProj4); - - if (!(syscoord = CreateSysCoord_GCSRS(-1, -1))) - { - goto onError; - } - SetSysCoordPrimeMeridian_GCSRS(syscoord, OSRGetPrimeMeridian(poSR, NULL)); - - a = OSRGetSemiMajor(poSR, NULL); - rf = OSRGetInvFlattening(poSR, NULL); - ell = _findSpheroid_GCSRS(a, rf); - if (GetInfoSpheroidID_GCSRS(ell) == -1) - { - CPLDebug("GEOCONCEPT", "Unsupported ellipsoid : %.4f %.10f", a, rf); - goto onError; - } - CPLDebug("GEOCONCEPT", "ellipsoid found : %s", - GetInfoSpheroidName_GCSRS(ell)); - - OSRGetTOWGS84(poSR, p, 7); - f = 1.0 - sqrt(1.0 - GetInfoSpheroidExcentricity_GCSRS(ell) * - GetInfoSpheroidExcentricity_GCSRS(ell)); - datum = _findDatum_GCSRS(p[0], p[1], p[2], - GetInfoSpheroidSemiMajor_GCSRS(ell), f); - if (GetInfoDatumID_GCSRS(datum) == -1) - { - CPLDebug("GEOCONCEPT", - "Unsupported datum : %.4f %.4f; %.4f a=%.4f rf=%.10f", p[0], - p[1], p[2], a, rf); - goto onError; - } - /* FIXME : WGS 84 and GRS 80 assimilation by Geoconcept : */ - if (GetInfoSpheroidID_GCSRS(ell) == 4) /* GRS 80 */ - { - datum = &(gk_asDatumList[31]); - } - else if (GetInfoSpheroidID_GCSRS(ell) == 9999) /* WGS 84 */ - { - datum = &(gk_asDatumList[3]); - } - CPLDebug("GEOCONCEPT", "datum found : %s", GetInfoDatumName_GCSRS(datum)); - SetSysCoordDatumID_GCSRS(syscoord, GetInfoDatumID_GCSRS(datum)); - - gcproj = _findProjection_GCSRS( - OSRIsGeographic(poSR) ? NULL : OSRGetAttrValue(poSR, "PROJECTION", 0), - OSRGetProjParm(poSR, SRS_PP_PSEUDO_STD_PARALLEL_1, 0.0, NULL)); - if (GetInfoProjID_GCSRS(gcproj) == -1) - { - CPLDebug("GEOCONCEPT", "Unsupported projection : %s", - OSRIsGeographic(poSR) - ? "GEOCS" - : OSRGetAttrValue(poSR, "PROJECTION", 0)); - goto onError; - } - CPLDebug("GEOCONCEPT", "projection : %s", GetInfoProjName_GCSRS(gcproj)); - SetSysCoordProjID_GCSRS(syscoord, GetInfoProjID_GCSRS(gcproj)); - - /* then overwrite them with projection specific parameters ... */ - if (OSRIsProjected(poSR)) - { - double v; - - SetSysCoordPrimeMeridian_GCSRS(syscoord, - OSRGetPrimeMeridian(poSR, NULL)); - SetSysCoordCentralMeridian_GCSRS( - syscoord, OSRGetProjParm(poSR, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL)); - SetSysCoordLatitudeOfOrigin_GCSRS( - syscoord, - OSRGetProjParm(poSR, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL)); - SetSysCoordStandardParallel1_GCSRS( - syscoord, - OSRGetProjParm(poSR, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL)); - SetSysCoordStandardParallel2_GCSRS( - syscoord, - OSRGetProjParm(poSR, SRS_PP_STANDARD_PARALLEL_2, 0.0, NULL)); - SetSysCoordFalseEasting_GCSRS( - syscoord, OSRGetProjParm(poSR, SRS_PP_FALSE_EASTING, 0.0, NULL)); - SetSysCoordFalseNorthing_GCSRS( - syscoord, OSRGetProjParm(poSR, SRS_PP_FALSE_NORTHING, 0.0, NULL)); - if ((v = OSRGetProjParm(poSR, SRS_PP_SCALE_FACTOR, 0.0, NULL)) != 0.0) - { - SetSysCoordScaleFactor_GCSRS(syscoord, v); - } - if ((v = OSRGetProjParm(poSR, SRS_PP_PSEUDO_STD_PARALLEL_1, 0.0, - NULL)) != 0.0) - { - /* should be SRS_PT_EQUIRECTANGULAR : */ - SetSysCoordScaleFactor_GCSRS(syscoord, cos(v * M_PI / 180.0)); - SetSysCoordStandardParallel1_GCSRS( - syscoord, v); /* allow keeping lat_ts sign */ - } - } - - /* Retrieve the syscoord : */ - if (!_findSysCoord_GCSRS(syscoord)) - { - CPLDebug("GEOCONCEPT", "invalid syscoord ?!"); - goto onError; - } - if (GetSysCoordSystemID_GCSRS(syscoord) == -1) - { - CPLDebug("GEOCONCEPT", "Cannot find syscoord"); - goto onError; - } - /* when SRS_PT_TRANSVERSE_MERCATOR, get zone : */ - if (GetSysCoordTimeZone_GCSRS(syscoord) == 0) - { - int pbNorth = 1; - SetSysCoordTimeZone_GCSRS(syscoord, OSRGetUTMZone(poSR, &pbNorth)); - } - - if (pszProj4) - { - CPLFree(pszProj4); - } - CPLDebug("GEOCONCEPT", "SysCoord value: %d:%d", - GetSysCoordSystemID_GCSRS(syscoord), - GetSysCoordTimeZone_GCSRS(syscoord)); - - return syscoord; - -onError: - if (pszProj4) - { - CPLDebug("GEOCONCEPT", "Unhandled spatial reference system '%s'.", - pszProj4); - CPLFree(pszProj4); - } - if (syscoord) - { - DestroySysCoord_GCSRS(&syscoord); - } - return NULL; -} /* OGRSpatialReference2SysCoord_GCSRS */ - -/* -------------------------------------------------------------------- */ -OGRSpatialReferenceH GCSRSAPI_CALL -SysCoord2OGRSpatialReference_GCSRS(GCSysCoord *syscoord) -{ - OGRSpatialReferenceH poSR; - const GCDatumInfo *datum = NULL; - const GCSpheroidInfo *ell = NULL; - int i; - double f; - - poSR = OSRNewSpatialReference(NULL); - OSRSetAxisMappingStrategy(poSR, OAMS_TRADITIONAL_GIS_ORDER); - - if (syscoord && GetSysCoordSystemID_GCSRS(syscoord) != -1) - { - switch (GetSysCoordProjID_GCSRS(syscoord)) - { - case 0: /* long/lat */ - break; - case 1: /* UTM */ - case 11: /* MGRS */ - case 12: /* TM */ - OSRSetTM(poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordScaleFactor_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 2: /* LCC 1SP */ - OSRSetLCC1SP(poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordScaleFactor_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 3: /* Bonne */ - OSRSetBonne(poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 4: /* Plate Caree */ - OSRSetEquirectangular( - poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 18: /* LCC 2SP */ - OSRSetLCC(poSR, GetSysCoordStandardParallel1_GCSRS(syscoord), - GetSysCoordStandardParallel2_GCSRS(syscoord), - GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 19: /* Gauss Schreiber : Reunion */ - OSRSetGaussSchreiberTMercator( - poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordScaleFactor_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 20: /* Polyconic */ - OSRSetPolyconic(poSR, - GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 21: /* Direct Mercator */ - OSRSetMercator(poSR, - GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordScaleFactor_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 22: /* Stereographic oblic */ - OSRSetOS(poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordScaleFactor_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 24: /* Miller */ - OSRSetMC(poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - case 26: /* Equi rectangular */ - OSRSetEquirectangular2( - poSR, GetSysCoordLatitudeOfOrigin_GCSRS(syscoord), - GetSysCoordCentralMeridian_GCSRS(syscoord), - GetSysCoordStandardParallel1_GCSRS(syscoord), - GetSysCoordFalseEasting_GCSRS(syscoord), - GetSysCoordFalseNorthing_GCSRS(syscoord)); - break; - default: - break; - } - if (GetSysCoordProjID_GCSRS(syscoord) > 0) - OSRSetProjCS(poSR, GetSysCoordName_GCSRS(syscoord)); - - for (i = 0, datum = &(gk_asDatumList[0]); - GetInfoDatumID_GCSRS(datum) != -1; - i++, datum = &(gk_asDatumList[i])) - { - if (GetInfoDatumID_GCSRS(datum) == - GetSysCoordDatumID_GCSRS(syscoord)) - break; - } - for (i = 0, ell = &(gk_asSpheroidList[0]); - GetInfoSpheroidID_GCSRS(ell) != -1; - i++, ell = &(gk_asSpheroidList[i])) - { - if (_areCompatibleSpheroids_GCSRS( - GetInfoSpheroidID_GCSRS(ell), - GetInfoDatumSpheroidID_GCSRS(datum))) - break; - } - /* FIXME : WGS 84 and GRS 80 assimilation by Geoconcept : */ - if (GetInfoDatumID_GCSRS(datum) == 4) /* WGS 84 */ - { - ell = &(gk_asSpheroidList[8]); - } - else if (GetInfoDatumID_GCSRS(datum) == 9984) /* GRS 80 */ - { - ell = &(gk_asSpheroidList[3]); - } - f = 1.0 - sqrt(1.0 - GetInfoSpheroidExcentricity_GCSRS(ell) * - GetInfoSpheroidExcentricity_GCSRS(ell)); - OSRSetGeogCS( - poSR, - GetSysCoordProjID_GCSRS(syscoord) != 0 || - !GetSysCoordName_GCSRS(syscoord) - ? "unnamed" - : GetSysCoordName_GCSRS(syscoord), - GetInfoDatumID_GCSRS(datum) >= 0 ? GetInfoDatumName_GCSRS(datum) - : "unknown", - GetInfoSpheroidID_GCSRS(ell) >= 0 ? GetInfoSpheroidName_GCSRS(ell) - : "unknown", - GetInfoSpheroidID_GCSRS(ell) >= 0 - ? GetInfoSpheroidSemiMajor_GCSRS(ell) - : 6378137.0, - GetInfoSpheroidID_GCSRS(ell) >= 0 ? (f == 0 ? 0 : 1 / f) - : 298.257223563, - "Greenwich", GetSysCoordPrimeMeridian_GCSRS(syscoord), - SRS_UA_DEGREE, CPLAtof(SRS_UA_DEGREE_CONV)); - /* As Geoconcept uses Molodensky, we've got only 3 out of 7 params for - * Bursa-Wolf : */ - /* the 4 missing Bursa-Wolf parameters have been added to the - * gk_asDatumList ! */ - if (GetInfoProjID_GCSRS(syscoord) > 0 && - GetInfoDatumID_GCSRS(datum) != -1) - { - OSRSetTOWGS84(poSR, GetInfoDatumShiftX_GCSRS(datum), - GetInfoDatumShiftY_GCSRS(datum), - GetInfoDatumShiftZ_GCSRS(datum), - GetInfoDatumRotationX_GCSRS(datum), - GetInfoDatumRotationY_GCSRS(datum), - GetInfoDatumRotationZ_GCSRS(datum), - 1e6 * GetInfoDatumScaleFactor_GCSRS(datum)); - } - } - - /* -------------------------------------------------------------------- */ - /* Report on translation. */ - /* -------------------------------------------------------------------- */ - { - char *pszWKT; - - OSRExportToWkt(poSR, &pszWKT); - if (pszWKT != NULL) - { - CPLDebug("GEOCONCEPT", - "This SysCoord value: %d:%d was translated to : %s", - syscoord ? GetSysCoordSystemID_GCSRS(syscoord) : -1, - syscoord ? GetSysCoordTimeZone_GCSRS(syscoord) : -1, - pszWKT); - CPLFree(pszWKT); - } - } - - return poSR; -} /* SysCoord2OGRSpatialReference_GCSRS */ diff --git a/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.h b/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.h deleted file mode 100644 index 30288d008333..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.h +++ /dev/null @@ -1,186 +0,0 @@ -/********************************************************************** - * $Id: geoconcept_syscoord.h$ - * - * Name: geoconcept_syscoord.h - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements translation between Geoconcept SysCoord - * and OGRSpatialRef format - * Language: C - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008, Even Rouault - * - * SPDX-License-Identifier: MIT - **********************************************************************/ -#ifndef GEOCONCEPT_SYSCOORD_H_INCLUDED -#define GEOCONCEPT_SYSCOORD_H_INCLUDED - -#include "ogr_srs_api.h" - -#ifdef GCSRS_DLLEXPORT -#define GCSRSAPI_CALL __declspec(dllexport) -#define GCSRSAPI_CALL1(x) __declspec(dllexport) x -#endif - -#ifndef GCSRSAPI_CALL -#define GCSRSAPI_CALL -#endif - -#ifndef GCSRSAPI_CALL1 -#define GCSRSAPI_CALL1(x) x GCSRSAPI_CALL -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* -------------------------------------------------------------------- */ - /* GCSRS API Types */ - /* -------------------------------------------------------------------- */ - typedef struct _tSpheroidInfo_GCSRS GCSpheroidInfo; - typedef struct _tDatumInfo_GCSRS GCDatumInfo; - typedef struct _tProjectionInfo_GCSRS GCProjectionInfo; - typedef struct _tSysCoord_GCSRS GCSysCoord; - - struct _tSpheroidInfo_GCSRS - { - const char *pszSpheroidName; - double dfA; /* semi major axis in meters */ - double dfE; /* eccentricity */ - int nEllipsoidID; - }; - - struct _tDatumInfo_GCSRS - { - const char *pszDatumName; - double dfShiftX; - double dfShiftY; - double dfShiftZ; - double dfRotX; - double dfRotY; - double dfRotZ; - double dfScaleFactor; - double dfDiffA; /* - * semi-major difference to-datum minus from-datum : - * http://home.hiwaay.net/~taylorc/bookshelf/math-science/geodesy/datum/transform/molodensky/ - */ - double dfDiffFlattening; /* - * Change in flattening : "to" minus "from" - */ - int nEllipsoidID; - int nDatumID; - }; - - struct _tProjectionInfo_GCSRS - { - const char *pszProjName; - /* TODO: Translate to English. */ - int nSphere; /* - * 1 = sphere de courbure - * 2 = sphere equatoriale - * 3 = sphere bitangeante - * 4 = sphere polaire nord - * 5 = sphere polaire sud - * 6 = Hotine - */ - int nProjID; - }; - - struct _tSysCoord_GCSRS - { - const char *pszSysCoordName; - const char *pszUnit; - - double dfPM; - /* inherited : */ - double dfLambda0; - double dfPhi0; - double dfk0; - double dfX0; - double dfY0; - double dfPhi1; - double dfPhi2; - - int nDatumID; - int nProjID; - int coordSystemID; - int timeZoneValue; /* when 0, replace by zone */ - }; - - /* -------------------------------------------------------------------- */ - /* GCSRS API Prototypes */ - /* -------------------------------------------------------------------- */ - -#define GetInfoSpheroidID_GCSRS(theSpheroid) (theSpheroid)->nEllipsoidID -#define GetInfoSpheroidName_GCSRS(theSpheroid) (theSpheroid)->pszSpheroidName -#define GetInfoSpheroidSemiMajor_GCSRS(theSpheroid) (theSpheroid)->dfA -#define GetInfoSpheroidExcentricity_GCSRS(theSpheroid) (theSpheroid)->dfE - -#define GetInfoDatumID_GCSRS(theDatum) (theDatum)->nDatumID -#define GetInfoDatumName_GCSRS(theDatum) (theDatum)->pszDatumName -#define GetInfoDatumShiftX_GCSRS(theDatum) (theDatum)->dfShiftX -#define GetInfoDatumShiftY_GCSRS(theDatum) (theDatum)->dfShiftY -#define GetInfoDatumShiftZ_GCSRS(theDatum) (theDatum)->dfShiftZ -#define GetInfoDatumDiffA_GCSRS(theDatum) (theDatum)->dfDiffA -#define GetInfoDatumRotationX_GCSRS(theDatum) (theDatum)->dfRotX -#define GetInfoDatumRotationY_GCSRS(theDatum) (theDatum)->dfRotY -#define GetInfoDatumRotationZ_GCSRS(theDatum) (theDatum)->dfRotZ -#define GetInfoDatumScaleFactor_GCSRS(theDatum) (theDatum)->dfScaleFactor -#define GetInfoDatumDiffFlattening_GCSRS(theDatum) (theDatum)->dfDiffFlattening -#define GetInfoDatumSpheroidID_GCSRS(theDatum) (theDatum)->nEllipsoidID - -#define GetInfoProjID_GCSRS(theProj) (theProj)->nProjID -#define GetInfoProjName_GCSRS(theProj) (theProj)->pszProjName -#define GetInfoProjSphereType_GCSRS(theProj) (theProj)->nSphere -#define GetInfoProjSpheroidID_GCSRS(theProj) (theProj)->nEllipsoidID - - GCSysCoord GCSRSAPI_CALL1(*) CreateSysCoord_GCSRS(int srsid, int timezone); - void GCSRSAPI_CALL DestroySysCoord_GCSRS(GCSysCoord **theSysCoord); -#define GetSysCoordSystemID_GCSRS(theSysCoord) (theSysCoord)->coordSystemID -#define SetSysCoordSystemID_GCSRS(theSysCoord, v) \ - (theSysCoord)->coordSystemID = (v) -#define GetSysCoordTimeZone_GCSRS(theSysCoord) (theSysCoord)->timeZoneValue -#define SetSysCoordTimeZone_GCSRS(theSysCoord, v) \ - (theSysCoord)->timeZoneValue = (v) -#define GetSysCoordName_GCSRS(theSysCoord) (theSysCoord)->pszSysCoordName -#define SetSysCoordName_GCSRS(theSysCoord, v) \ - (theSysCoord)->pszSysCoordName = (v) -#define GetSysCoordUnit_GCSRS(theSysCoord) (theSysCoord)->pszUnit -#define SetSysCoordUnit_GCSRS(theSysCoord, v) (theSysCoord)->pszUnit = (v) -#define GetSysCoordPrimeMeridian_GCSRS(theSysCoord) (theSysCoord)->dfPM -#define SetSysCoordPrimeMeridian_GCSRS(theSysCoord, v) (theSysCoord)->dfPM = (v) -#define GetSysCoordCentralMeridian_GCSRS(theSysCoord) (theSysCoord)->dfLambda0 -#define SetSysCoordCentralMeridian_GCSRS(theSysCoord, v) \ - (theSysCoord)->dfLambda0 = (v) -#define GetSysCoordLatitudeOfOrigin_GCSRS(theSysCoord) (theSysCoord)->dfPhi0 -#define SetSysCoordLatitudeOfOrigin_GCSRS(theSysCoord, v) \ - (theSysCoord)->dfPhi0 = (v) -#define GetSysCoordStandardParallel1_GCSRS(theSysCoord) (theSysCoord)->dfPhi1 -#define SetSysCoordStandardParallel1_GCSRS(theSysCoord, v) \ - (theSysCoord)->dfPhi1 = (v) -#define GetSysCoordStandardParallel2_GCSRS(theSysCoord) (theSysCoord)->dfPhi2 -#define SetSysCoordStandardParallel2_GCSRS(theSysCoord, v) \ - (theSysCoord)->dfPhi2 = (v) -#define GetSysCoordScaleFactor_GCSRS(theSysCoord) (theSysCoord)->dfk0 -#define SetSysCoordScaleFactor_GCSRS(theSysCoord, v) (theSysCoord)->dfk0 = (v) -#define GetSysCoordFalseEasting_GCSRS(theSysCoord) (theSysCoord)->dfX0 -#define SetSysCoordFalseEasting_GCSRS(theSysCoord, v) (theSysCoord)->dfX0 = (v) -#define GetSysCoordFalseNorthing_GCSRS(theSysCoord) (theSysCoord)->dfY0 -#define SetSysCoordFalseNorthing_GCSRS(theSysCoord, v) (theSysCoord)->dfY0 = (v) -#define GetSysCoordDatumID_GCSRS(theSysCoord) (theSysCoord)->nDatumID -#define SetSysCoordDatumID_GCSRS(theSysCoord, v) (theSysCoord)->nDatumID = (v) -#define GetSysCoordProjID_GCSRS(theSysCoord) (theSysCoord)->nProjID -#define SetSysCoordProjID_GCSRS(theSysCoord, v) (theSysCoord)->nProjID = (v) - - GCSysCoord GCSRSAPI_CALL1(*) - OGRSpatialReference2SysCoord_GCSRS(OGRSpatialReferenceH poSR); - OGRSpatialReferenceH GCSRSAPI_CALL - SysCoord2OGRSpatialReference_GCSRS(GCSysCoord *syscoord); - -#ifdef __cplusplus -} -#endif - -#endif /* ndef GEOCONCEPT_SYSCOORD_H_INCLUDED */ diff --git a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.cpp b/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.cpp deleted file mode 100644 index 9fed6a8c57e1..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.cpp +++ /dev/null @@ -1,542 +0,0 @@ -/****************************************************************************** - * - * Name: ogrgeoconceptdatasource.h - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements OGRGeoconceptDataSource class. - * Language: C++ - * - ****************************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008, Even Rouault - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "cpl_conv.h" -#include "cpl_string.h" -#include "ogrgeoconceptdatasource.h" -#include "ogrgeoconceptlayer.h" - -/************************************************************************/ -/* OGRGeoconceptDataSource() */ -/************************************************************************/ - -OGRGeoconceptDataSource::OGRGeoconceptDataSource() - : _papoLayers(nullptr), _nLayers(0), _pszGCT(nullptr), - _pszDirectory(nullptr), _pszExt(nullptr), _papszOptions(nullptr), - _bSingleNewFile(false), _bUpdate(false), _hGXT(nullptr) -{ -} - -/************************************************************************/ -/* ~OGRGeoconceptDataSource() */ -/************************************************************************/ - -OGRGeoconceptDataSource::~OGRGeoconceptDataSource() - -{ - for (int i = 0; i < _nLayers; i++) - { - delete _papoLayers[i]; - } - CPLFree(_papoLayers); - CPLFree(_pszGCT); - CPLFree(_pszDirectory); - CPLFree(_pszExt); - CSLDestroy(_papszOptions); - - if (_hGXT) - { - Close_GCIO(&_hGXT); - } -} - -/************************************************************************/ -/* Open() */ -/* */ -/* Open an existing file. */ -/************************************************************************/ - -int OGRGeoconceptDataSource::Open(const char *pszName, bool bTestOpen, - bool bUpdate) - -{ - /* -------------------------------------------------------------------- */ - /* Is the given path a directory or a regular file? */ - /* -------------------------------------------------------------------- */ - VSIStatBufL sStat; - - if (VSIStatL(pszName, &sStat) != 0 || - (!VSI_ISDIR(sStat.st_mode) && !VSI_ISREG(sStat.st_mode))) - { - if (!bTestOpen) - { - CPLError(CE_Failure, CPLE_AppDefined, - "%s is neither a file or directory, " - "Geoconcept access failed.", - pszName); - } - - return FALSE; - } - - if (VSI_ISDIR(sStat.st_mode)) - { - CPLDebug("GEOCONCEPT", - "%s is a directory, Geoconcept access is not yet supported.", - pszName); - - return FALSE; - } - - SetDescription(pszName); - - if (VSI_ISREG(sStat.st_mode)) - { - _bSingleNewFile = false; - _bUpdate = bUpdate; - if (!LoadFile(_bUpdate ? "a+t" : "rt")) - { - CPLDebug("GEOCONCEPT", - "Failed to open Geoconcept %s." - " It may be corrupt.", - pszName); - - return FALSE; - } - - return TRUE; - } - - return _nLayers > 0; -} - -/************************************************************************/ -/* LoadFile() */ -/************************************************************************/ - -int OGRGeoconceptDataSource::LoadFile(const char *pszMode) - -{ - if (_pszExt == nullptr) - { - _pszExt = CPLStrdup(CPLGetExtensionSafe(GetDescription()).c_str()); - } - CPLStrlwr(_pszExt); - - if (!_pszDirectory) - _pszDirectory = CPLStrdup(CPLGetPathSafe(GetDescription()).c_str()); - - if ((_hGXT = Open_GCIO(GetDescription(), _pszExt, pszMode, _pszGCT)) == - nullptr) - { - return FALSE; - } - - /* Collect layers : */ - GCExportFileMetadata *Meta = GetGCMeta_GCIO(_hGXT); - if (Meta) - { - const int nC = CountMetaTypes_GCIO(Meta); - - if (nC > 0) - { - for (int iC = 0; iC < nC; iC++) - { - GCType *aClass = GetMetaType_GCIO(Meta, iC); - if (aClass) - { - const int nS = CountTypeSubtypes_GCIO(aClass); - if (nS) - { - for (int iS = 0; iS < nS; iS++) - { - GCSubType *aSubclass = - GetTypeSubtype_GCIO(aClass, iS); - if (aSubclass) - { - OGRGeoconceptLayer *poFile = - new OGRGeoconceptLayer; - if (poFile->Open(aSubclass) != OGRERR_NONE) - { - delete poFile; - return FALSE; - } - - /* Add layer to data source layers list */ - _papoLayers = - static_cast( - CPLRealloc( - _papoLayers, - sizeof(OGRGeoconceptLayer *) * - (_nLayers + 1))); - _papoLayers[_nLayers++] = poFile; - - CPLDebug("GEOCONCEPT", "nLayers=%d - last=[%s]", - _nLayers, - poFile->GetLayerDefn()->GetName()); - } - } - } - } - } - } - } - - return TRUE; -} - -/************************************************************************/ -/* Create() */ -/* */ -/* Create a new dataset. */ -/* */ -/* Options (-dsco) : */ -/* EXTENSION : gxt|txt */ -/* CONFIG : path to GCT file */ -/************************************************************************/ - -int OGRGeoconceptDataSource::Create(const char *pszName, char **papszOptions) - -{ - _papszOptions = CSLDuplicate(papszOptions); - - const char *pszConf = CSLFetchNameValue(papszOptions, "CONFIG"); - if (pszConf != nullptr) - { - _pszGCT = CPLStrdup(pszConf); - } - - _pszExt = (char *)CSLFetchNameValue(papszOptions, "EXTENSION"); - const char *pszExtension = CSLFetchNameValue(papszOptions, "EXTENSION"); - if (pszExtension == nullptr) - { - _pszExt = CPLStrdup(CPLGetExtensionSafe(pszName).c_str()); - } - else - { - _pszExt = CPLStrdup(pszExtension); - } - - if (strlen(_pszExt) == 0) - { - if (VSIMkdir(pszName, 0755) != 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Directory %s already exists" - " as geoconcept datastore or" - " is made up of a non existing list of directories.", - pszName); - - return FALSE; - } - _pszDirectory = CPLStrdup(pszName); - CPLFree(_pszExt); - _pszExt = CPLStrdup("gxt"); - char *pszbName = CPLStrdup(CPLGetBasenameSafe(pszName).c_str()); - if (strlen(pszbName) == 0) - { /* pszName ends with '/' */ - CPLFree(pszbName); - char *pszNameDup = CPLStrdup(pszName); - pszNameDup[strlen(pszName) - 2] = '\0'; - pszbName = CPLStrdup(CPLGetBasenameSafe(pszNameDup).c_str()); - CPLFree(pszNameDup); - } - SetDescription( - CPLFormFilenameSafe(_pszDirectory, pszbName, nullptr).c_str()); - CPLFree(pszbName); - } - else - { - _pszDirectory = CPLStrdup(CPLGetPathSafe(pszName).c_str()); - SetDescription(pszName); - } - - /* -------------------------------------------------------------------- */ - /* Create a new single file. */ - /* OGRGeoconceptDriver::ICreateLayer() will do the job. */ - /* -------------------------------------------------------------------- */ - _bSingleNewFile = true; - - if (!LoadFile("wt")) - { - CPLDebug("GEOCONCEPT", "Failed to create Geoconcept %s.", pszName); - - return FALSE; - } - - return TRUE; -} - -/************************************************************************/ -/* ICreateLayer() */ -/* */ -/* Options (-lco) : */ -/* FEATURETYPE : TYPE.SUBTYPE */ -/************************************************************************/ - -OGRLayer * -OGRGeoconceptDataSource::ICreateLayer(const char *pszLayerName, - const OGRGeomFieldDefn *poGeomFieldDefn, - CSLConstList papszOptions) - -{ - if (_hGXT == nullptr) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Internal Error : null datasource handler."); - return nullptr; - } - - const auto poSRS = - poGeomFieldDefn ? poGeomFieldDefn->GetSpatialRef() : nullptr; - if (poSRS == nullptr && !_bUpdate) - { - CPLError(CE_Failure, CPLE_NotSupported, - "SRS is mandatory of creating a Geoconcept Layer."); - return nullptr; - } - - /* - * pszLayerName Class.Subclass if -nln option used, otherwise file name - */ - const char *pszFeatureType = nullptr; - char pszln[512]; - - if (!(pszFeatureType = CSLFetchNameValue(papszOptions, "FEATURETYPE"))) - { - if (!pszLayerName || !strchr(pszLayerName, '.')) - { - snprintf(pszln, 511, "%s.%s", - pszLayerName ? pszLayerName : "ANONCLASS", - pszLayerName ? pszLayerName : "ANONSUBCLASS"); - pszln[511] = '\0'; - pszFeatureType = pszln; - } - else - pszFeatureType = pszLayerName; - } - - char **ft = CSLTokenizeString2(pszFeatureType, ".", 0); - if (!ft || CSLCount(ft) != 2) - { - CSLDestroy(ft); - CPLError(CE_Failure, CPLE_AppDefined, - "Feature type name '%s' is incorrect." - "Correct syntax is : Class.Subclass.", - pszFeatureType); - return nullptr; - } - - /* -------------------------------------------------------------------- */ - /* Figure out what type of layer we need. */ - /* -------------------------------------------------------------------- */ - GCTypeKind gcioFeaType; - GCDim gcioDim = v2D_GCIO; - - const auto eType = poGeomFieldDefn ? poGeomFieldDefn->GetType() : wkbNone; - if (eType == wkbUnknown) - gcioFeaType = vUnknownItemType_GCIO; - else if (eType == wkbPoint) - gcioFeaType = vPoint_GCIO; - else if (eType == wkbLineString) - gcioFeaType = vLine_GCIO; - else if (eType == wkbPolygon) - gcioFeaType = vPoly_GCIO; - else if (eType == wkbMultiPoint) - gcioFeaType = vPoint_GCIO; - else if (eType == wkbMultiLineString) - gcioFeaType = vLine_GCIO; - else if (eType == wkbMultiPolygon) - gcioFeaType = vPoly_GCIO; - else if (eType == wkbPoint25D) - { - gcioFeaType = vPoint_GCIO; - gcioDim = v3DM_GCIO; - } - else if (eType == wkbLineString25D) - { - gcioFeaType = vLine_GCIO; - gcioDim = v3DM_GCIO; - } - else if (eType == wkbPolygon25D) - { - gcioFeaType = vPoly_GCIO; - gcioDim = v3DM_GCIO; - } - else if (eType == wkbMultiPoint25D) - { - gcioFeaType = vPoint_GCIO; - gcioDim = v3DM_GCIO; - } - else if (eType == wkbMultiLineString25D) - { - gcioFeaType = vLine_GCIO; - gcioDim = v3DM_GCIO; - } - else if (eType == wkbMultiPolygon25D) - { - gcioFeaType = vPoly_GCIO; - gcioDim = v3DM_GCIO; - } - else - { - CSLDestroy(ft); - CPLError(CE_Failure, CPLE_NotSupported, - "Geometry type of '%s' not supported in Geoconcept files.", - OGRGeometryTypeToName(eType)); - return nullptr; - } - - /* - * As long as we use the CONFIG, creating a layer implies the - * layer name to exist in the CONFIG as "Class.Subclass". - * Removing the CONFIG, implies on-the-fly-creation of layers... - */ - OGRGeoconceptLayer *poFile = nullptr; - - if (_nLayers > 0) - for (int iLayer = 0; iLayer < _nLayers; iLayer++) - { - poFile = reinterpret_cast(GetLayer(iLayer)); - if (poFile != nullptr && - EQUAL(poFile->GetLayerDefn()->GetName(), pszFeatureType)) - { - break; - } - poFile = nullptr; - } - if (!poFile) - { - GCSubType *aSubclass = nullptr; - GCExportFileMetadata *m = GetGCMeta_GCIO(_hGXT); - - if (!m) - { - if (!(m = CreateHeader_GCIO())) - { - CSLDestroy(ft); - return nullptr; - } - SetMetaExtent_GCIO( - m, CreateExtent_GCIO(HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL)); - SetGCMeta_GCIO(_hGXT, m); - } - if (FindFeature_GCIO(_hGXT, pszFeatureType)) - { - CSLDestroy(ft); - CPLError(CE_Failure, CPLE_AppDefined, "Layer '%s' already exists.", - pszFeatureType); - return nullptr; - } - if (!AddType_GCIO(_hGXT, ft[0], -1L)) - { - CSLDestroy(ft); - CPLError(CE_Failure, CPLE_AppDefined, "Failed to add layer '%s'.", - pszFeatureType); - return nullptr; - } - if (!(aSubclass = AddSubType_GCIO(_hGXT, ft[0], ft[1], -1L, gcioFeaType, - gcioDim))) - { - CSLDestroy(ft); - CPLError(CE_Failure, CPLE_AppDefined, "Failed to add layer '%s'.", - pszFeatureType); - return nullptr; - } - /* complete feature type with private fields : */ - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kIdentifier_GCIO, -100, - vIntFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kClass_GCIO, -101, - vMemoFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kSubclass_GCIO, -102, - vMemoFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kName_GCIO, -103, - vMemoFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kNbFields_GCIO, -104, - vIntFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kX_GCIO, -105, - vRealFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kY_GCIO, -106, - vRealFld_GCIO, nullptr, nullptr); - /* user's fields will be added with Layer->CreateField() method ... */ - switch (gcioFeaType) - { - case vPoint_GCIO: - break; - case vLine_GCIO: - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kXP_GCIO, -107, - vRealFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kYP_GCIO, -108, - vRealFld_GCIO, nullptr, nullptr); - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kGraphics_GCIO, - -109, vUnknownItemType_GCIO, nullptr, - nullptr); - break; - default: - AddSubTypeField_GCIO(_hGXT, ft[0], ft[1], -1L, kGraphics_GCIO, - -109, vUnknownItemType_GCIO, nullptr, - nullptr); - break; - } - SetSubTypeGCHandle_GCIO(aSubclass, _hGXT); - - /* Add layer to data source layers list */ - poFile = new OGRGeoconceptLayer; - if (poFile->Open(aSubclass) != OGRERR_NONE) - { - CSLDestroy(ft); - delete poFile; - return nullptr; - } - - _papoLayers = static_cast(CPLRealloc( - _papoLayers, sizeof(OGRGeoconceptLayer *) * (_nLayers + 1))); - _papoLayers[_nLayers++] = poFile; - - CPLDebug("GEOCONCEPT", "nLayers=%d - last=[%s]", _nLayers, - poFile->GetLayerDefn()->GetName()); - } - CSLDestroy(ft); - - /* -------------------------------------------------------------------- */ - /* Assign the coordinate system (if provided) */ - /* -------------------------------------------------------------------- */ - if (poSRS != nullptr) - { - auto poSRSClone = poSRS->Clone(); - poFile->SetSpatialRef(poSRSClone); - poSRSClone->Release(); - } - - return poFile; -} - -/************************************************************************/ -/* TestCapability() */ -/************************************************************************/ - -int OGRGeoconceptDataSource::TestCapability(const char *pszCap) - -{ - if (EQUAL(pszCap, ODsCCreateLayer)) - return TRUE; - else if (EQUAL(pszCap, ODsCZGeometries)) - return TRUE; - - return FALSE; -} - -/************************************************************************/ -/* GetLayer() */ -/************************************************************************/ - -OGRLayer *OGRGeoconceptDataSource::GetLayer(int iLayer) - -{ - if (iLayer < 0 || iLayer >= GetLayerCount()) - return nullptr; - - OGRLayer *poFile = _papoLayers[iLayer]; - return poFile; -} diff --git a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.h b/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.h deleted file mode 100644 index f166626ffffd..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdatasource.h +++ /dev/null @@ -1,62 +0,0 @@ -/********************************************************************** - * $Id: ogrgeoconceptdatasource.h$ - * - * Name: ogrgeoconceptdatasource.h - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements OGRGeoconceptDataSource class. - * Language: C++ - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * - * SPDX-License-Identifier: MIT - **********************************************************************/ - -#include "ogrsf_frmts.h" -#include "ogrgeoconceptlayer.h" - -#ifndef GEOCONCEPT_OGR_DATASOURCE_H_INCLUDED_ -#define GEOCONCEPT_OGR_DATASOURCE_H_INCLUDED_ - -/**********************************************************************/ -/* OGCGeoconceptDataSource Class */ -/**********************************************************************/ -class OGRGeoconceptDataSource : public GDALDataset -{ - private: - OGRGeoconceptLayer **_papoLayers; - int _nLayers; - - char *_pszGCT; - char *_pszDirectory; - char *_pszExt; - char **_papszOptions; - bool _bSingleNewFile; - bool _bUpdate; - GCExportFileH *_hGXT; - - public: - OGRGeoconceptDataSource(); - ~OGRGeoconceptDataSource(); - - int Open(const char *pszName, bool bTestOpen, bool bUpdate); - int Create(const char *pszName, char **papszOptions); - - int GetLayerCount() override - { - return _nLayers; - } - - OGRLayer *GetLayer(int iLayer) override; - // OGRErr DeleteLayer( int iLayer ); - int TestCapability(const char *pszCap) override; - - OGRLayer *ICreateLayer(const char *pszName, - const OGRGeomFieldDefn *poGeomFieldDefn, - CSLConstList papszOptions) override; - - private: - int LoadFile(const char *); -}; - -#endif /* GEOCONCEPT_OGR_DATASOURCE_H_INCLUDED_ */ diff --git a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdriver.cpp b/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdriver.cpp deleted file mode 100644 index c739dbc99bc4..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptdriver.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/****************************************************************************** - * - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements OGRGeoconceptDriver class. - * Author: Didier Richard, didier.richard@ign.fr - * Language: C++ - * - ****************************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "cpl_conv.h" -#include "cpl_string.h" -#include "ogrgeoconceptdatasource.h" - -/************************************************************************/ -/* Open() */ -/************************************************************************/ - -static GDALDataset *OGRGeoconceptDriverOpen(GDALOpenInfo *poOpenInfo) - -{ - const char *pszFilename = poOpenInfo->pszFilename; -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* -------------------------------------------------------------------- */ - /* We will only consider .gxt and .txt files. */ - /* -------------------------------------------------------------------- */ - const std::string osExtension = CPLGetExtensionSafe(pszFilename); - if (!EQUAL(osExtension.c_str(), "gxt") && - !EQUAL(osExtension.c_str(), "txt")) - { - return nullptr; - } -#endif - - auto poDS = new OGRGeoconceptDataSource(); - - if (!poDS->Open(pszFilename, true, poOpenInfo->eAccess == GA_Update)) - { - delete poDS; - return nullptr; - } - return poDS; -} - -/************************************************************************/ -/* CreateDataSource() */ -/* */ -/* Options (-dsco) : */ -/* EXTENSION=GXT|TXT (default GXT) */ -/************************************************************************/ - -static GDALDataset *OGRGeoconceptDriverCreate(const char *pszName, - int /* nXSize */, - int /* nYSize */, - int /* nBandCount */, - GDALDataType, char **papszOptions) - -{ - VSIStatBufL sStat; - /* int bSingleNewFile = FALSE; */ - - if (pszName == nullptr || strlen(pszName) == 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Invalid datasource name (null or empty)"); - return nullptr; - } - - /* -------------------------------------------------------------------- */ - /* Is the target a valid existing directory? */ - /* -------------------------------------------------------------------- */ - if (VSIStatL(pszName, &sStat) == 0) - { - if (!VSI_ISDIR(sStat.st_mode)) - { - CPLError(CE_Failure, CPLE_AppDefined, - "%s is not a valid existing directory.", pszName); - return nullptr; - } - } - - /* -------------------------------------------------------------------- */ - /* Does it end with the extension .gxt indicating the user likely */ - /* wants to create a single file set? */ - /* -------------------------------------------------------------------- */ - else if (EQUAL(CPLGetExtensionSafe(pszName).c_str(), "gxt") || - EQUAL(CPLGetExtensionSafe(pszName).c_str(), "txt")) - { - /* bSingleNewFile = TRUE; */ - } - - /* -------------------------------------------------------------------- */ - /* Return a new OGRDataSource() */ - /* -------------------------------------------------------------------- */ - OGRGeoconceptDataSource *poDS = new OGRGeoconceptDataSource(); - if (!poDS->Create(pszName, papszOptions)) - { - delete poDS; - return nullptr; - } - return poDS; -} - -/************************************************************************/ -/* OGRGeoconceptDriverDelete() */ -/************************************************************************/ - -static CPLErr OGRGeoconceptDriverDelete(const char *pszDataSource) - -{ - VSIStatBufL sStatBuf; - static const char *const apszExtensions[] = {"gxt", "txt", "gct", - "gcm", "gcr", nullptr}; - - if (VSIStatL(pszDataSource, &sStatBuf) != 0) - { - CPLError(CE_Failure, CPLE_AppDefined, - "%s does not appear to be a file or directory.", - pszDataSource); - - return CE_Failure; - } - - if (VSI_ISREG(sStatBuf.st_mode) && - (EQUAL(CPLGetExtensionSafe(pszDataSource).c_str(), "gxt") || - EQUAL(CPLGetExtensionSafe(pszDataSource).c_str(), "txt"))) - { - for (int iExt = 0; apszExtensions[iExt] != nullptr; iExt++) - { - const std::string osFile = - CPLResetExtensionSafe(pszDataSource, apszExtensions[iExt]); - if (VSIStatL(osFile.c_str(), &sStatBuf) == 0) - VSIUnlink(osFile.c_str()); - } - } - else if (VSI_ISDIR(sStatBuf.st_mode)) - { - char **papszDirEntries = VSIReadDir(pszDataSource); - - for (int iFile = 0; - papszDirEntries != nullptr && papszDirEntries[iFile] != nullptr; - iFile++) - { - if (CSLFindString( - const_cast(apszExtensions), - CPLGetExtensionSafe(papszDirEntries[iFile]).c_str()) != -1) - { - VSIUnlink(CPLFormFilenameSafe(pszDataSource, - papszDirEntries[iFile], nullptr) - .c_str()); - } - } - - CSLDestroy(papszDirEntries); - - VSIRmdir(pszDataSource); - } - - return CE_None; -} - -/************************************************************************/ -/* RegisterOGRGeoconcept() */ -/************************************************************************/ - -void RegisterOGRGeoconcept() - -{ - if (GDALGetDriverByName("Geoconcept")) - return; - - GDALDriver *poDriver = new GDALDriver(); - poDriver->SetDescription("Geoconcept"); - poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Geoconcept"); - poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); - poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); - poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); - poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "gxt txt"); - poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); - - poDriver->SetMetadataItem( - GDAL_DMD_CREATIONOPTIONLIST, - "" - " " - " "); - - poDriver->SetMetadataItem(GDAL_DS_LAYER_CREATIONOPTIONLIST, - "" - " "); - poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); - poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); - - poDriver->pfnOpen = OGRGeoconceptDriverOpen; - poDriver->pfnCreate = OGRGeoconceptDriverCreate; - poDriver->pfnDelete = OGRGeoconceptDriverDelete; - - GetGDALDriverManager()->RegisterDriver(poDriver); -} diff --git a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp b/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp deleted file mode 100644 index 3d75c6b96a68..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp +++ /dev/null @@ -1,658 +0,0 @@ -/****************************************************************************** - * - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements OGRGeoconceptLayer class. - * Author: Didier Richard, didier.richard@ign.fr - * Language: C++ - * - ****************************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * Copyright (c) 2008, Even Rouault - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "cpl_conv.h" -#include "cpl_string.h" -#include "ogrgeoconceptlayer.h" - -/************************************************************************/ -/* OGRGeoconceptLayer() */ -/************************************************************************/ - -OGRGeoconceptLayer::OGRGeoconceptLayer() - : _poFeatureDefn(nullptr), _gcFeature(nullptr) -{ -} - -/************************************************************************/ -/* ~OGRGeoconceptLayer() */ -/************************************************************************/ - -OGRGeoconceptLayer::~OGRGeoconceptLayer() - -{ - if (_poFeatureDefn) - { - CPLDebug("GEOCONCEPT", "%ld features on layer %s.", - GetSubTypeNbFeatures_GCIO(_gcFeature), - _poFeatureDefn->GetName()); - - _poFeatureDefn->Release(); - } - - _gcFeature = nullptr; /* deleted when OGCGeoconceptDatasource destroyed */ -} - -/************************************************************************/ -/* Open() */ -/************************************************************************/ - -OGRErr OGRGeoconceptLayer::Open(GCSubType *Subclass) - -{ - _gcFeature = Subclass; - if (GetSubTypeFeatureDefn_GCIO(_gcFeature)) - { - _poFeatureDefn = reinterpret_cast( - GetSubTypeFeatureDefn_GCIO(_gcFeature)); - SetDescription(_poFeatureDefn->GetName()); - _poFeatureDefn->Reference(); - } - else - { - char pszln[512]; - snprintf(pszln, 511, "%s.%s", GetSubTypeName_GCIO(_gcFeature), - GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))); - pszln[511] = '\0'; - - _poFeatureDefn = new OGRFeatureDefn(pszln); - SetDescription(_poFeatureDefn->GetName()); - _poFeatureDefn->Reference(); - _poFeatureDefn->SetGeomType(wkbUnknown); - - const int n = CountSubTypeFields_GCIO(_gcFeature); - if (n > 0) - { - OGRFieldType oft; - for (int i = 0; i < n; i++) - { - GCField *aField = GetSubTypeField_GCIO(_gcFeature, i); - if (aField) - { - if (IsPrivateField_GCIO(aField)) - continue; - switch (GetFieldKind_GCIO(aField)) - { - case vIntFld_GCIO: - case vPositionFld_GCIO: - oft = OFTInteger; - break; - case vRealFld_GCIO: - case vLengthFld_GCIO: - case vAreaFld_GCIO: - oft = OFTReal; - break; - case vDateFld_GCIO: - oft = OFTDate; - break; - case vTimeFld_GCIO: - oft = OFTTime; - break; - case vMemoFld_GCIO: - case vChoiceFld_GCIO: - case vInterFld_GCIO: - default: - oft = OFTString; - break; - } - OGRFieldDefn ofd(GetFieldName_GCIO(aField), oft); - _poFeatureDefn->AddFieldDefn(&ofd); - } - } - } - SetSubTypeFeatureDefn_GCIO(_gcFeature, (OGRFeatureDefnH)_poFeatureDefn); - _poFeatureDefn->Reference(); - } - - if (_poFeatureDefn->GetGeomFieldCount() > 0) - _poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(GetSpatialRef()); - - return OGRERR_NONE; -} - -/************************************************************************/ -/* ResetReading() */ -/************************************************************************/ - -void OGRGeoconceptLayer::ResetReading() - -{ - Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature), _gcFeature); -} - -/************************************************************************/ -/* GetNextFeature() */ -/************************************************************************/ - -OGRFeature *OGRGeoconceptLayer::GetNextFeature() - -{ - OGRFeature *poFeature = nullptr; - - for (;;) - { - if (!(poFeature = (OGRFeature *)ReadNextFeature_GCIO(_gcFeature))) - { - /* - * As several features are embed in the Geoconcept file, - * when reaching the end of the feature type, resetting - * the reader would allow reading other features : - * ogrinfo -ro export.gxt FT1 FT2 ... - * will be all features for all features types ! - */ - Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature), nullptr); - break; - } - if ((m_poFilterGeom == nullptr || - FilterGeometry(poFeature->GetGeometryRef())) && - (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate(poFeature))) - { - break; - } - delete poFeature; - } - - CPLDebug("GEOCONCEPT", - "FID : " CPL_FRMT_GIB "\n" - "%s : %s", - poFeature ? poFeature->GetFID() : -1L, - poFeature && poFeature->GetFieldCount() > 0 - ? poFeature->GetFieldDefnRef(0)->GetNameRef() - : "-", - poFeature && poFeature->GetFieldCount() > 0 - ? poFeature->GetFieldAsString(0) - : ""); - - return poFeature; -} - -/************************************************************************/ -/* OGRGeoconceptLayer_GetCompatibleFieldName() */ -/************************************************************************/ - -static char *OGRGeoconceptLayer_GetCompatibleFieldName(const char *pszName) -{ - char *pszCompatibleName = CPLStrdup(pszName); - for (int i = 0; pszCompatibleName[i] != 0; i++) - { - if (pszCompatibleName[i] == ' ') - pszCompatibleName[i] = '_'; - } - return pszCompatibleName; -} - -/************************************************************************/ -/* ICreateFeature() */ -/************************************************************************/ - -OGRErr OGRGeoconceptLayer::ICreateFeature(OGRFeature *poFeature) - -{ - OGRGeometry *poGeom = poFeature->GetGeometryRef(); - - if (poGeom == nullptr) - { - CPLError( - CE_Warning, CPLE_NotSupported, - "NULL geometry not supported in Geoconcept, feature skipped.\n"); - return OGRERR_NONE; - } - - OGRwkbGeometryType eGt = poGeom->getGeometryType(); - switch (wkbFlatten(eGt)) - { - case wkbPoint: - case wkbMultiPoint: - if (GetSubTypeKind_GCIO(_gcFeature) == vUnknownItemType_GCIO) - { - SetSubTypeKind_GCIO(_gcFeature, vPoint_GCIO); - } - else if (GetSubTypeKind_GCIO(_gcFeature) != vPoint_GCIO) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Can't write non ponctual feature in a ponctual " - "Geoconcept layer %s.\n", - _poFeatureDefn->GetName()); - return OGRERR_FAILURE; - } - break; - case wkbLineString: - case wkbMultiLineString: - if (GetSubTypeKind_GCIO(_gcFeature) == vUnknownItemType_GCIO) - { - SetSubTypeKind_GCIO(_gcFeature, vLine_GCIO); - } - else if (GetSubTypeKind_GCIO(_gcFeature) != vLine_GCIO) - { - CPLError( - CE_Failure, CPLE_NotSupported, - "Can't write non linear feature in a linear Geoconcept " - "layer %s.\n", - _poFeatureDefn->GetName()); - return OGRERR_FAILURE; - } - break; - case wkbPolygon: - case wkbMultiPolygon: - if (GetSubTypeKind_GCIO(_gcFeature) == vUnknownItemType_GCIO) - { - SetSubTypeKind_GCIO(_gcFeature, vPoly_GCIO); - } - else if (GetSubTypeKind_GCIO(_gcFeature) != vPoly_GCIO) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Can't write non polygonal feature in a polygonal " - "Geoconcept layer %s.\n", - _poFeatureDefn->GetName()); - return OGRERR_FAILURE; - } - break; - default: - CPLError(CE_Warning, CPLE_AppDefined, - "Geometry type %s not supported in Geoconcept, " - "feature skipped.\n", - OGRGeometryTypeToName(eGt)); - return OGRERR_NONE; - } - if (GetSubTypeDim_GCIO(_gcFeature) == vUnknown3D_GCIO) - { - if (poGeom->getCoordinateDimension() == 3) - { - SetSubTypeDim_GCIO(_gcFeature, v3D_GCIO); - } - else - { - SetSubTypeDim_GCIO(_gcFeature, v2D_GCIO); - } - } - - int nbGeom = 0; - bool isSingle = false; - - switch (wkbFlatten(eGt)) - { - case wkbPoint: - case wkbLineString: - case wkbPolygon: - nbGeom = 1; - isSingle = true; - break; - case wkbMultiPoint: - case wkbMultiLineString: - case wkbMultiPolygon: - nbGeom = poGeom->toGeometryCollection()->getNumGeometries(); - isSingle = false; - break; - default: - nbGeom = 0; - isSingle = false; - break; - } - - /* 1st feature, let's write header : */ - if (GetGCMode_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature)) == - vWriteAccess_GCIO && - GetFeatureCount(TRUE) == 0) - if (WriteHeader_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature)) == nullptr) - { - return OGRERR_FAILURE; - } - - if (nbGeom > 0) - { - for (int iGeom = 0; iGeom < nbGeom; iGeom++) - { - int nextField = StartWritingFeature_GCIO( - _gcFeature, - isSingle ? static_cast(poFeature->GetFID()) : OGRNullFID); - while (nextField != WRITECOMPLETED_GCIO) - { - if (nextField == WRITEERROR_GCIO) - { - return OGRERR_FAILURE; - } - if (nextField == GEOMETRYEXPECTED_GCIO) - { - OGRGeometry *poGeomPart = - isSingle - ? poGeom - : poGeom->toGeometryCollection()->getGeometryRef( - iGeom); - nextField = WriteFeatureGeometry_GCIO( - _gcFeature, (OGRGeometryH)poGeomPart); - } - else - { - GCField *theField = - GetSubTypeField_GCIO(_gcFeature, nextField); - /* for each field, find out its mapping ... */ - int nF = poFeature->GetFieldCount(); - if (nF > 0) - { - int iF = 0; - for (; iF < nF; iF++) - { - OGRFieldDefn *poField = - poFeature->GetFieldDefnRef(iF); - char *pszName = - OGRGeoconceptLayer_GetCompatibleFieldName( - poField->GetNameRef()); - if (EQUAL(pszName, GetFieldName_GCIO(theField))) - { - CPLFree(pszName); - nextField = WriteFeatureFieldAsString_GCIO( - _gcFeature, nextField, - poFeature->IsFieldSetAndNotNull(iF) - ? poFeature->GetFieldAsString(iF) - : nullptr); - break; - } - CPLFree(pszName); - } - if (iF == nF) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Can't find a field attached to %s on " - "Geoconcept layer %s.\n", - GetFieldName_GCIO(theField), - _poFeatureDefn->GetName()); - return OGRERR_FAILURE; - } - } - else - { - nextField = WRITECOMPLETED_GCIO; - } - } - } - StopWritingFeature_GCIO(_gcFeature); - } - } - - return OGRERR_NONE; -} - -/************************************************************************/ -/* GetSpatialRef() */ -/************************************************************************/ - -OGRSpatialReference *OGRGeoconceptLayer::GetSpatialRef() - -{ - GCExportFileH *hGXT = GetSubTypeGCHandle_GCIO(_gcFeature); - if (!hGXT) - return nullptr; - GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT); - if (!Meta) - return nullptr; - return (OGRSpatialReference *)GetMetaSRS_GCIO(Meta); -} - -/************************************************************************/ -/* GetFeatureCount() */ -/* */ -/* If a spatial filter is in effect, we turn control over to */ -/* the generic counter. Otherwise we return the total count. */ -/************************************************************************/ - -GIntBig OGRGeoconceptLayer::GetFeatureCount(int bForce) - -{ - if (m_poFilterGeom != nullptr || m_poAttrQuery != nullptr) - return OGRLayer::GetFeatureCount(bForce); - - return GetSubTypeNbFeatures_GCIO(_gcFeature); -} - -/************************************************************************/ -/* GetExtent() */ -/************************************************************************/ - -OGRErr OGRGeoconceptLayer::GetExtent(OGREnvelope *psExtent, - CPL_UNUSED int bForce) -{ - GCExtent *theExtent = GetSubTypeExtent_GCIO(_gcFeature); - if (!theExtent) - return OGRERR_FAILURE; - psExtent->MinX = GetExtentULAbscissa_GCIO(theExtent); - psExtent->MinY = GetExtentLROrdinate_GCIO(theExtent); - psExtent->MaxX = GetExtentLRAbscissa_GCIO(theExtent); - psExtent->MaxY = GetExtentULOrdinate_GCIO(theExtent); - - return OGRERR_NONE; -} - -/************************************************************************/ -/* TestCapability() */ -/************************************************************************/ - -int OGRGeoconceptLayer::TestCapability(const char *pszCap) - -{ - if (EQUAL(pszCap, OLCRandomRead)) - return FALSE; // the GetFeature() method does not work for this layer. - // TODO - - else if (EQUAL(pszCap, OLCSequentialWrite)) - return TRUE; // the CreateFeature() method works for this layer. - - else if (EQUAL(pszCap, OLCRandomWrite)) - return FALSE; // the SetFeature() method is not operational on this - // layer. - - else if (EQUAL(pszCap, OLCFastSpatialFilter)) - return FALSE; // this layer does not implement spatial filtering - // efficiently. - - else if (EQUAL(pszCap, OLCFastFeatureCount)) - return FALSE; // this layer can not return a feature count efficiently. - // FIXME - - else if (EQUAL(pszCap, OLCFastGetExtent)) - return FALSE; // this layer can not return its data extent efficiently. - // FIXME - - else if (EQUAL(pszCap, OLCFastSetNextByIndex)) - return FALSE; // this layer can not perform the SetNextByIndex() call - // efficiently. - - else if (EQUAL(pszCap, OLCDeleteFeature)) - return FALSE; - - else if (EQUAL(pszCap, OLCCreateField)) - return TRUE; - - else if (EQUAL(pszCap, OLCZGeometries)) - return TRUE; - - return FALSE; -} - -/************************************************************************/ -/* CreateField() */ -/************************************************************************/ - -OGRErr OGRGeoconceptLayer::CreateField(const OGRFieldDefn *poField, - CPL_UNUSED int bApproxOK) -{ - if (GetGCMode_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature)) == vReadAccess_GCIO) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Can't create fields on a read-only Geoconcept layer.\n"); - return OGRERR_FAILURE; - } - - /* -------------------------------------------------------------------- */ - /* Add field to layer */ - /* -------------------------------------------------------------------- */ - - { - /* check whether field exists ... */ - char *pszName = - OGRGeoconceptLayer_GetCompatibleFieldName(poField->GetNameRef()); - - GCField *theField = FindFeatureField_GCIO(_gcFeature, pszName); - if (!theField) - { - if (GetFeatureCount(TRUE) > 0) - { - CPLError(CE_Failure, CPLE_NotSupported, - "Can't create field '%s' on existing Geoconcept layer " - "'%s.%s'.\n", - pszName, GetSubTypeName_GCIO(_gcFeature), - GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))); - CPLFree(pszName); - return OGRERR_FAILURE; - } - if (GetSubTypeNbFields_GCIO(_gcFeature) == -1) - SetSubTypeNbFields_GCIO(_gcFeature, 0L); - if (!(theField = AddSubTypeField_GCIO( - GetSubTypeGCHandle_GCIO(_gcFeature), - GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature)), - GetSubTypeName_GCIO(_gcFeature), - FindFeatureFieldIndex_GCIO(_gcFeature, kNbFields_GCIO) + - GetSubTypeNbFields_GCIO(_gcFeature) + 1, - pszName, GetSubTypeNbFields_GCIO(_gcFeature) - 999L, - vUnknownItemType_GCIO, nullptr, nullptr))) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Field '%s' could not be created for Feature %s.%s.\n", - pszName, GetSubTypeName_GCIO(_gcFeature), - GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))); - CPLFree(pszName); - return OGRERR_FAILURE; - } - SetSubTypeNbFields_GCIO(_gcFeature, - GetSubTypeNbFields_GCIO(_gcFeature) + 1); - _poFeatureDefn->AddFieldDefn(poField); - } - else - { - if (_poFeatureDefn->GetFieldIndex(GetFieldName_GCIO(theField)) == - -1) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Field %s not found for Feature %s.%s.\n", - GetFieldName_GCIO(theField), - GetSubTypeName_GCIO(_gcFeature), - GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))); - CPLFree(pszName); - return OGRERR_FAILURE; - } - } - - CPLFree(pszName); - pszName = nullptr; - - /* check/update type ? */ - if (GetFieldKind_GCIO(theField) == vUnknownItemType_GCIO) - { - switch (poField->GetType()) - { - case OFTInteger: - SetFieldKind_GCIO(theField, vIntFld_GCIO); - break; - case OFTReal: - SetFieldKind_GCIO(theField, vRealFld_GCIO); - break; - case OFTDate: - SetFieldKind_GCIO(theField, vDateFld_GCIO); - break; - case OFTTime: - case OFTDateTime: - SetFieldKind_GCIO(theField, vTimeFld_GCIO); - break; - case OFTString: - SetFieldKind_GCIO(theField, vMemoFld_GCIO); - break; - case OFTIntegerList: - case OFTRealList: - case OFTStringList: - case OFTBinary: - default: - CPLError(CE_Failure, CPLE_NotSupported, - "Can't create fields of type %s on Geoconcept " - "feature %s.\n", - OGRFieldDefn::GetFieldTypeName(poField->GetType()), - _poFeatureDefn->GetName()); - return OGRERR_FAILURE; - } - } - } - - return OGRERR_NONE; -} - -/************************************************************************/ -/* SyncToDisk() */ -/************************************************************************/ - -OGRErr OGRGeoconceptLayer::SyncToDisk() - -{ - FFlush_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature)); - return OGRERR_NONE; -} - -/************************************************************************/ -/* SetSpatialRef() */ -/************************************************************************/ - -void OGRGeoconceptLayer::SetSpatialRef(OGRSpatialReference *poSpatialRef) - -{ - OGRSpatialReference *poSRS = GetSpatialRef(); - - GCExportFileH *hGXT = GetSubTypeGCHandle_GCIO(_gcFeature); - if (hGXT) - { - GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT); - if (Meta) - { - if (poSRS) - poSRS->Release(); - SetMetaSRS_GCIO(Meta, nullptr); - } - else - return; - } - else - { - return; - } - - poSRS = poSpatialRef->Clone(); - poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); - GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT); - GCSysCoord *os = GetMetaSysCoord_GCIO(Meta); - GCSysCoord *ns = OGRSpatialReference2SysCoord_GCSRS( - reinterpret_cast(poSRS)); - - if (os && ns && GetSysCoordSystemID_GCSRS(os) != -1 && - (GetSysCoordSystemID_GCSRS(os) != GetSysCoordSystemID_GCSRS(ns) || - GetSysCoordTimeZone_GCSRS(os) != GetSysCoordTimeZone_GCSRS(ns))) - { - CPLError(CE_Warning, CPLE_AppDefined, - "Can't change SRS on Geoconcept layers.\n"); - DestroySysCoord_GCSRS(&ns); - poSRS->Release(); - return; - } - - if (os) - DestroySysCoord_GCSRS(&os); - SetMetaSysCoord_GCIO(Meta, ns); - SetMetaSRS_GCIO(Meta, (OGRSpatialReferenceH)poSRS); - return; -} diff --git a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.h b/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.h deleted file mode 100644 index 0d53a1c84c0a..000000000000 --- a/ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.h +++ /dev/null @@ -1,80 +0,0 @@ -/********************************************************************** - * $Id: ogrgeoconceptlayer.h$ - * - * Name: ogrgeoconceptlayer.h - * Project: OpenGIS Simple Features Reference Implementation - * Purpose: Implements OGRGeoconceptLayer class. - * Language: C++ - * - ********************************************************************** - * Copyright (c) 2007, Geoconcept and IGN - * - * SPDX-License-Identifier: MIT - **********************************************************************/ - -#include "ogrsf_frmts.h" -#include "geoconcept.h" - -#ifndef GEOCONCEPT_OGR_LAYER_H_INCLUDED_ -#define GEOCONCEPT_OGR_LAYER_H_INCLUDED_ - -/**********************************************************************/ -/* OGCGeoconceptLayer Class */ -/**********************************************************************/ -class OGRGeoconceptLayer final : public OGRLayer -{ - private: - OGRFeatureDefn *_poFeatureDefn; - - GCSubType *_gcFeature; - - public: - OGRGeoconceptLayer(); - virtual ~OGRGeoconceptLayer(); - - OGRErr Open(GCSubType *Subclass); - - // OGRGeometry* GetSpatialFilter( ); - // void SetSpatialFilter( OGRGeometry* poGeomIn ); - // void SetSpatialFilterRect( double dfMinX, double - // dfMinY, double dfMaxX, double dfMaxY ); OGRErr SetAttributeFilter( - // const char* pszQuery ); - void ResetReading() override; - OGRFeature *GetNextFeature() override; - // OGRErr SetNextByIndex( GIntBig nIndex ); - - // OGRFeature* GetFeature( GIntBig nFID ); - // OGRErr ISetFeature( OGRFeature* poFeature ); - // OGRErr DeleteFeature( GIntBig nFID ); - OGRErr ICreateFeature(OGRFeature *poFeature) override; - - OGRFeatureDefn *GetLayerDefn() override - { - return _poFeatureDefn; - } // FIXME - - OGRSpatialReference *GetSpatialRef() override; - GIntBig GetFeatureCount(int bForce = TRUE) override; - OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override; - - virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, - int bForce) override - { - return OGRLayer::GetExtent(iGeomField, psExtent, bForce); - } - - int TestCapability(const char *pszCap) override; - // const char* GetInfo( const char* pszTag ); - OGRErr CreateField(const OGRFieldDefn *poField, - int bApproxOK = TRUE) override; - OGRErr SyncToDisk() override; - // OGRStyleTable* GetStyleTable( ); - // void SetStyleTableDirectly( OGRStyleTable* - // poStyleTable ); void SetStyleTable( OGRStyleTable* - // poStyleTable ); const char* GetFIDColumn( ); const char* - // GetGeometryColumn( ); - - void SetSpatialRef(OGRSpatialReference *poSpatialRef); -}; - -#endif /* GEOCONCEPT_OGR_LAYER_H_INCLUDED_ */ diff --git a/ogr/ogrsf_frmts/ogrsf_frmts.h b/ogr/ogrsf_frmts/ogrsf_frmts.h index fff499d8d862..82f925e56f07 100644 --- a/ogr/ogrsf_frmts/ogrsf_frmts.h +++ b/ogr/ogrsf_frmts/ogrsf_frmts.h @@ -714,7 +714,6 @@ void CPL_DLL RegisterOGRIDB(); void DeclareDeferredOGRIDBPlugin(); void CPL_DLL RegisterOGRGMT(); void CPL_DLL RegisterOGRGPX(); -void CPL_DLL RegisterOGRGeoconcept(); void CPL_DLL RegisterOGRNAS(); void CPL_DLL RegisterOGRGeoRSS(); void CPL_DLL RegisterOGRVFK();