From 5bc6a91276e3d68a83334d3073f11769396dd386 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 28 Jan 2025 23:17:09 +0100 Subject: [PATCH] Remove SVG driver --- autotest/ogr/data/svg/test.svg | 25 - autotest/ogr/ogr_svg.py | 66 -- doc/source/drivers/vector/index.rst | 1 - doc/source/drivers/vector/svg.rst | 36 - ogr/ogrsf_frmts/CMakeLists.txt | 1 - ogr/ogrsf_frmts/generic/ogrregisterall.cpp | 3 - ogr/ogrsf_frmts/ogrsf_frmts.h | 1 - ogr/ogrsf_frmts/svg/CMakeLists.txt | 7 - ogr/ogrsf_frmts/svg/ogr_svg.h | 154 ---- ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp | 246 ------ ogr/ogrsf_frmts/svg/ogrsvgdriver.cpp | 72 -- ogr/ogrsf_frmts/svg/ogrsvglayer.cpp | 843 --------------------- 12 files changed, 1455 deletions(-) delete mode 100644 autotest/ogr/data/svg/test.svg delete mode 100755 autotest/ogr/ogr_svg.py delete mode 100644 doc/source/drivers/vector/svg.rst delete mode 100644 ogr/ogrsf_frmts/svg/CMakeLists.txt delete mode 100644 ogr/ogrsf_frmts/svg/ogr_svg.h delete mode 100644 ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp delete mode 100644 ogr/ogrsf_frmts/svg/ogrsvgdriver.cpp delete mode 100644 ogr/ogrsf_frmts/svg/ogrsvglayer.cpp diff --git a/autotest/ogr/data/svg/test.svg b/autotest/ogr/data/svg/test.svg deleted file mode 100644 index f9d4c444a4ca..000000000000 --- a/autotest/ogr/data/svg/test.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - 2009-11-10 03:44:57+00:00 - residential - 1988060.0 - 44075465 - - - 24024676 - footway - 2008-04-29 07:30:01+01:00 - - - yes - 2009-06-28 10:18:25+01:00 - Northwest Animal Facility - 368166329 - - - - \ No newline at end of file diff --git a/autotest/ogr/ogr_svg.py b/autotest/ogr/ogr_svg.py deleted file mode 100755 index 34f4d48ea6f5..000000000000 --- a/autotest/ogr/ogr_svg.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env pytest -############################################################################### -# -# Project: GDAL/OGR Test Suite -# Purpose: Test SVG driver functionality. -# Author: Even Rouault -# -############################################################################### -# Copyright (c) 2011, Even Rouault -# -# SPDX-License-Identifier: MIT -############################################################################### - - -import ogrtest -import pytest - -from osgeo import ogr - -pytestmark = pytest.mark.require_driver("SVG") - - -def test_ogr_svg_1(): - - svg_ds = ogr.Open("data/svg/test.svg") - - assert svg_ds is not None - - assert svg_ds.GetLayerCount() == 3, "wrong number of layers" - - lyr = svg_ds.GetLayerByName("points") - assert lyr.GetFeatureCount() == 1, "wrong number of features" - - feat = lyr.GetNextFeature() - - if feat.GetFieldAsString("building") != "yes": - feat.DumpReadable() - pytest.fail() - - ogrtest.check_feature_geometry( - feat, - "POINT (-13610535.695141600444913 4561593.930507560260594)", - max_error=0.0001, - ) - - lyr = svg_ds.GetLayerByName("lines") - assert lyr.GetFeatureCount() == 1, "wrong number of features" - - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "LINESTRING (-13609855.59 4561479.26,-13609856.21 4561474.27,-13609860.03 4561468.87,-13609865.74 4561465.69,-13609869.54 4561465.06)", - max_error=0.0001, - ) - - lyr = svg_ds.GetLayerByName("polygons") - assert lyr.GetFeatureCount() == 1, "wrong number of features" - - feat = lyr.GetNextFeature() - - ogrtest.check_feature_geometry( - feat, - "POLYGON ((-13610027.72 4562403.66,-13609661.58 4562462.95,-13609671.33 4562516.4,-13609676.11 4562532.65,-13609692.36 4562552.71,-13609711.46 4562609.08,-13609721.97 4562634.89,-13609727.7 4562650.16,-13609727.7 4562666.41,-13609716.23 4562699.85,-13609698.09 4562758.14,-13609697.13 4562771.51,-13609706.68 4562811.64,-13609720.06 4562843.18,-13609723.88 4562863.23,-13609725.8 4562891.91,-13609721.02 4562919.61,-13609713.37 4562938.72,-13609701.91 4562954.97,-13609688.53 4562968.34,-13609668.47 4562979.8,-13609614.96 4562993.17,-13609589.16 4563005.6,-13609552.85 4563037.14,-13609530.88 4563053.37,-13609474.5 4563076.3,-13609487.81 4563109.75,-13609491.89 4563149.38,-13609478.48 4563157.66,-13609467.67 4563171.31,-13609462.25 4563189.21,-13609420.46 4563189.32,-13609401.89 4563191.92,-13609395.2 4563201.47,-13609287.23 4563264.53,-13609303.48 4563291.29,-13609330.23 4563313.26,-13609339.78 4563326.63,-13609342.66 4563340.96,-13609344.56 4563458.48,-13609341.7 4563482.38,-13609322.59 4563518.68,-13609304.43 4563574.1,-13609290.1 4563592.26,-13609289.15 4563615.19,-13609290.1 4563655.32,-13609287.23 4563675.38,-13609271.95 4563703.09,-13609263.35 4563739.4,-13609258.57 4563762.32,-13609250.73 4563760.48,-13609226.84 4563718.43,-13609214.42 4563688.81,-13609204.87 4563661.1,-13609191.49 4563641.03,-13609170.47 4563629.56,-13609137.03 4563632.44,-13609109.32 4563648.68,-13609097.85 4563676.39,-13609100.72 4563712.7,-13609102.63 4563800.59,-13609116.0 4563819.7,-13609156.13 4563850.28,-13609151.55 4563861.7,-13609044.54 4563885.58,-13609057.92 4563945.78,-13609058.88 4563959.15,-13609031.17 4563987.81,-13609014.93 4563969.66,-13608988.17 4563981.13,-13608918.43 4563946.74,-13608834.46 4563870.62,-13608756.43 4563811.52,-13608716.02 4563488.23,-13608439.74 4563228.22,-13608483.69 4563167.08,-13608471.27 4563156.56,-13608461.72 4563132.68,-13608457.89 4563102.1,-13608460.76 4563077.26,-13608464.58 4563054.33,-13608444.52 4563044.78,-13608428.02 4562925.57,-13608408.91 4562672.38,-13608471.97 4562671.42,-13608514.96 4562653.27,-13608586.63 4562653.27,-13608728.76 4562628.85,-13609304.17 4562530.01,-13609354.81 4562401.98,-13609349.2 4562281.92,-13609401.52 4562278.13,-13609426.46 4562253.26,-13609385.39 4562165.98,-13609374.88 4561992.09,-13609361.7 4561946.97,-13609413.36 4561935.48,-13609402.85 4561884.85,-13609429.6 4561890.57,-13609487.88 4561880.07,-13609495.53 4561931.65,-13609442.02 4561942.18,-13609454.44 4562017.65,-13609601.59 4561997.59,-13609881.1 4561949.97,-13609858.97 4561817.17,-13609878.07 4561814.31,-13609891.08 4561883.51,-13609912.1 4561880.63,-13609918.79 4561924.59,-13609922.03 4561942.33,-13609949.37 4561938.35,-13609971.5 4562072.19,-13610108.74 4562049.23,-13610117.33 4562098.92,-13610151.73 4562094.14,-13610154.59 4562109.42,-13610224.34 4562097.96,-13610222.43 4562079.81,-13610381.03 4562053.05,-13610401.1 4562051.15,-13610386.77 4561907.82,-13610286.45 4561921.2,-13610210.01 4561869.6,-13610188.04 4561873.42,-13610173.7 4561778.84,-13610177.52 4561770.24,-13610184.21 4561764.51,-13610403.97 4561729.15,-13610429.77 4561711.0,-13610442.18 4561704.31,-13610574.04 4561683.29,-13610579.77 4561748.26,-13610620.86 4561745.4,-13610652.39 4562062.61,-13610802.4 4562037.77,-13610765.13 4561654.62,-13610860.68 4561641.25,-13610892.21 4562001.46,-13610848.26 4562007.19,-13610850.37 4562027.78,-13610870.24 4562264.22,-13610821.87 4562270.93,-13610819.96 4562245.14,-13610749.26 4562250.86,-13610754.03 4562306.29,-13610861.04 4562285.26,-13610864.69 4562319.19,-13610873.3 4562318.24,-13610882.85 4562463.47,-13610835.12 4562470.5,-13610816.0 4562473.37,-13610816.96 4562481.96,-13610737.66 4562493.43,-13610746.26 4562564.13,-13610782.56 4562558.4,-13610784.48 4562580.38,-13610826.52 4562575.6,-13610828.43 4562590.89,-13610845.63 4562588.98,-13610891.49 4562583.24,-13610895.3 4562621.46,-13610829.38 4562629.11,-13610844.67 4562786.76,-13610613.45 4562823.06,-13610570.46 4562334.82,-13610699.56 4562312.97,-13610695.75 4562293.86,-13610689.66 4562256.58,-13610543.47 4562263.26,-13610548.25 4562316.77,-13610487.1 4562326.32,-13610483.27 4562297.66,-13610443.14 4562303.38,-13610446.97 4562333.96,-13610027.72 4562403.66))", - max_error=0.0001, - ) diff --git a/doc/source/drivers/vector/index.rst b/doc/source/drivers/vector/index.rst index 411189072692..fdb498273279 100644 --- a/doc/source/drivers/vector/index.rst +++ b/doc/source/drivers/vector/index.rst @@ -96,7 +96,6 @@ Vector drivers shapefile sosi sqlite - svg sxf tiger tiledb diff --git a/doc/source/drivers/vector/svg.rst b/doc/source/drivers/vector/svg.rst deleted file mode 100644 index 35035954ef20..000000000000 --- a/doc/source/drivers/vector/svg.rst +++ /dev/null @@ -1,36 +0,0 @@ -.. _vector.svg: - -SVG - Scalable Vector Graphics -============================== - -.. shortname:: SVG - -.. build_dependencies:: libexpat - -OGR has support for SVG reading (if GDAL is built with *expat* library -support). - -Currently, it will only read SVG files that are the output from -Cloudmade Vector Stream Server - -All coordinates are relative to the Pseudo-mercator SRS (EPSG:3857). - -The driver will return 3 layers : - -- points -- lines -- polygons - -Driver capabilities -------------------- - -.. supports_georeferencing:: - -.. supports_virtualio:: - -See Also --------- - -- `W3C SVG page `__ -- `Cloudmade vector - documentation `__ diff --git a/ogr/ogrsf_frmts/CMakeLists.txt b/ogr/ogrsf_frmts/CMakeLists.txt index 15fc491e7665..628ba65ea1ea 100644 --- a/ogr/ogrsf_frmts/CMakeLists.txt +++ b/ogr/ogrsf_frmts/CMakeLists.txt @@ -103,7 +103,6 @@ ogr_dependent_driver(sdts SDTS "GDAL_ENABLE_DRIVER_SDTS") # XML drivers ogr_dependent_driver(gpx "GPX - GPS Exchange Format" "GDAL_USE_EXPAT") ogr_dependent_driver(gmlas GMLAS "GDAL_USE_XERCESC;OGR_ENABLE_DRIVER_PGDUMP") -ogr_dependent_driver(svg "Scalable Vector Graphics" "GDAL_USE_EXPAT") ogr_dependent_driver(csw CSW "GDAL_USE_CURL") ogr_dependent_driver(dwg DWG "GDAL_USE_TEIGHA") ogr_dependent_driver(filegdb FileGDB "GDAL_USE_FILEGDB") diff --git a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp index 843197c6dac5..c6e2dd967f4a 100644 --- a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp +++ b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp @@ -174,9 +174,6 @@ void OGRRegisterAllInternal() #ifdef EDIGEO_ENABLED RegisterOGREDIGEO(); #endif -#ifdef SVG_ENABLED - RegisterOGRSVG(); -#endif #ifdef IDRISI_ENABLED RegisterOGRIdrisi(); #endif diff --git a/ogr/ogrsf_frmts/ogrsf_frmts.h b/ogr/ogrsf_frmts/ogrsf_frmts.h index 0d774075baa4..e0299dd618e1 100644 --- a/ogr/ogrsf_frmts/ogrsf_frmts.h +++ b/ogr/ogrsf_frmts/ogrsf_frmts.h @@ -733,7 +733,6 @@ void CPL_DLL RegisterOGROAPIF(); void CPL_DLL RegisterOGRSOSI(); void DeclareDeferredOGRSOSIPlugin(); void CPL_DLL RegisterOGREDIGEO(); -void CPL_DLL RegisterOGRSVG(); void CPL_DLL RegisterOGRIdrisi(); void CPL_DLL RegisterOGRXLS(); void DeclareDeferredOGRXLSPlugin(); diff --git a/ogr/ogrsf_frmts/svg/CMakeLists.txt b/ogr/ogrsf_frmts/svg/CMakeLists.txt deleted file mode 100644 index ea755746daa0..000000000000 --- a/ogr/ogrsf_frmts/svg/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_gdal_driver(TARGET ogr_SVG SOURCES ogr_svg.h ogrsvgdatasource.cpp ogrsvgdriver.cpp ogrsvglayer.cpp PLUGIN_CAPABLE - NO_DEPS) -gdal_standard_includes(ogr_SVG) -if (GDAL_USE_EXPAT) - target_compile_definitions(ogr_SVG PRIVATE -DHAVE_EXPAT=1) - gdal_target_link_libraries(ogr_SVG PRIVATE ${EXPAT_TARGET}) -endif () diff --git a/ogr/ogrsf_frmts/svg/ogr_svg.h b/ogr/ogrsf_frmts/svg/ogr_svg.h deleted file mode 100644 index 5c679c4f68bb..000000000000 --- a/ogr/ogrsf_frmts/svg/ogr_svg.h +++ /dev/null @@ -1,154 +0,0 @@ -/****************************************************************************** - * - * Project: SVG Translator - * Purpose: Definition of classes for OGR .svg driver. - * Author: Even Rouault, even dot rouault at spatialys.com - * - ****************************************************************************** - * Copyright (c) 2011-2013, Even Rouault - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#ifndef OGR_SVG_H_INCLUDED -#define OGR_SVG_H_INCLUDED - -#include "ogrsf_frmts.h" - -#ifdef HAVE_EXPAT -#include "ogr_expat.h" -#endif - -class OGRSVGDataSource; - -typedef enum -{ - SVG_POINTS, - SVG_LINES, - SVG_POLYGONS, -} SVGGeometryType; - -constexpr int PARSER_BUF_SIZE = 8192; - -/************************************************************************/ -/* OGRSVGLayer */ -/************************************************************************/ - -class OGRSVGLayer final : public OGRLayer -{ - OGRFeatureDefn *poFeatureDefn; - OGRSpatialReference *poSRS; -#ifdef HAVE_EXPAT - OGRSVGDataSource *poDS; -#endif - CPLString osLayerName; - - SVGGeometryType svgGeomType; - - int nTotalFeatures; - int nNextFID; - VSILFILE *fpSVG; // Large file API. - -#ifdef HAVE_EXPAT - XML_Parser oParser; - XML_Parser oSchemaParser; -#endif - char *pszSubElementValue; - int nSubElementValueLen; - int iCurrentField; - - OGRFeature *poFeature; - OGRFeature **ppoFeatureTab; - int nFeatureTabLength; - int nFeatureTabIndex; - - int depthLevel; - int interestingDepthLevel; - bool inInterestingElement; - - bool bStopParsing; -#ifdef HAVE_EXPAT - int nWithoutEventCounter; - int nDataHandlerCounter; - - OGRSVGLayer *poCurLayer; -#endif - - private: - void LoadSchema(); - - public: - OGRSVGLayer(const char *pszFilename, const char *layerName, - SVGGeometryType svgGeomType, OGRSVGDataSource *poDS); - virtual ~OGRSVGLayer(); - - virtual void ResetReading() override; - virtual OGRFeature *GetNextFeature() override; - - virtual const char *GetName() override - { - return osLayerName.c_str(); - } - - virtual OGRwkbGeometryType GetGeomType() override; - - virtual GIntBig GetFeatureCount(int bForce = TRUE) override; - - virtual OGRFeatureDefn *GetLayerDefn() override; - - virtual int TestCapability(const char *) override; - -#ifdef HAVE_EXPAT - void startElementCbk(const char *pszName, const char **ppszAttr); - void endElementCbk(const char *pszName); - void dataHandlerCbk(const char *data, int nLen); - - void startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr); - void endElementLoadSchemaCbk(const char *pszName); - void dataHandlerLoadSchemaCbk(const char *data, int nLen); -#endif -}; - -/************************************************************************/ -/* OGRSVGDataSource */ -/************************************************************************/ - -typedef enum -{ - SVG_VALIDITY_UNKNOWN, - SVG_VALIDITY_INVALID, - SVG_VALIDITY_VALID -} OGRSVGValidity; - -class OGRSVGDataSource final : public GDALDataset -{ - OGRSVGLayer **papoLayers; - int nLayers; - -#ifdef HAVE_EXPAT - OGRSVGValidity eValidity; - int bIsCloudmade; - XML_Parser oCurrentParser; - int nDataHandlerCounter; -#endif - - public: - OGRSVGDataSource(); - virtual ~OGRSVGDataSource(); - - int Open(const char *pszFilename); - - virtual int GetLayerCount() override - { - return nLayers; - } - - virtual OGRLayer *GetLayer(int) override; - -#ifdef HAVE_EXPAT - void startElementValidateCbk(const char *pszName, const char **ppszAttr); - void dataHandlerValidateCbk(const char *data, int nLen); -#endif -}; - -#endif /* ndef OGR_SVG_H_INCLUDED */ diff --git a/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp b/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp deleted file mode 100644 index 6b5105fc0043..000000000000 --- a/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/****************************************************************************** - * - * Project: SVG Translator - * Purpose: Implements OGRSVGDataSource class - * Author: Even Rouault, even dot rouault at spatialys.com - * - ****************************************************************************** - * Copyright (c) 2011, Even Rouault - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "ogr_svg.h" -#include "cpl_conv.h" - -/************************************************************************/ -/* OGRSVGDataSource() */ -/************************************************************************/ - -OGRSVGDataSource::OGRSVGDataSource() - : papoLayers(nullptr), nLayers(0) -#ifdef HAVE_EXPAT - , - eValidity(SVG_VALIDITY_UNKNOWN), bIsCloudmade(false), - oCurrentParser(nullptr), nDataHandlerCounter(0) -#endif -{ -} - -/************************************************************************/ -/* ~OGRSVGDataSource() */ -/************************************************************************/ - -OGRSVGDataSource::~OGRSVGDataSource() - -{ - for (int i = 0; i < nLayers; i++) - delete papoLayers[i]; - CPLFree(papoLayers); -} - -/************************************************************************/ -/* GetLayer() */ -/************************************************************************/ - -OGRLayer *OGRSVGDataSource::GetLayer(int iLayer) - -{ - if (iLayer < 0 || iLayer >= nLayers) - return nullptr; - else - return papoLayers[iLayer]; -} - -#ifdef HAVE_EXPAT - -/************************************************************************/ -/* startElementValidateCbk() */ -/************************************************************************/ - -void OGRSVGDataSource::startElementValidateCbk(const char *pszNameIn, - const char **ppszAttr) -{ - if (eValidity == SVG_VALIDITY_UNKNOWN) - { - if (strcmp(pszNameIn, "svg") == 0) - { - eValidity = SVG_VALIDITY_VALID; - for (int i = 0; ppszAttr[i] != nullptr; i += 2) - { - if (strcmp(ppszAttr[i], "xmlns:cm") == 0 && - strcmp(ppszAttr[i + 1], "http://cloudmade.com/") == 0) - { - bIsCloudmade = true; - break; - } - } - } - else - { - eValidity = SVG_VALIDITY_INVALID; - } - } -} - -/************************************************************************/ -/* dataHandlerValidateCbk() */ -/************************************************************************/ - -void OGRSVGDataSource::dataHandlerValidateCbk(CPL_UNUSED const char *data, - CPL_UNUSED int nLen) -{ - nDataHandlerCounter++; - if (nDataHandlerCounter >= PARSER_BUF_SIZE) - { - CPLError(CE_Failure, CPLE_AppDefined, - "File probably corrupted (million laugh pattern)"); - XML_StopParser(oCurrentParser, XML_FALSE); - } -} - -static void XMLCALL startElementValidateCbk(void *pUserData, - const char *pszName, - const char **ppszAttr) -{ - OGRSVGDataSource *poDS = (OGRSVGDataSource *)pUserData; - poDS->startElementValidateCbk(pszName, ppszAttr); -} - -static void XMLCALL dataHandlerValidateCbk(void *pUserData, const char *data, - int nLen) -{ - OGRSVGDataSource *poDS = (OGRSVGDataSource *)pUserData; - poDS->dataHandlerValidateCbk(data, nLen); -} -#endif - -/************************************************************************/ -/* Open() */ -/************************************************************************/ - -int OGRSVGDataSource::Open(const char *pszFilename) - -{ -#ifdef HAVE_EXPAT - /* -------------------------------------------------------------------- */ - /* Try to open the file. */ - /* -------------------------------------------------------------------- */ - CPLString osFilename; // keep in that scope - if (EQUAL(CPLGetExtensionSafe(pszFilename).c_str(), "svgz") && - strstr(pszFilename, "/vsigzip/") == nullptr) - { - osFilename = CPLString("/vsigzip/") + pszFilename; - pszFilename = osFilename.c_str(); - } - - VSILFILE *fp = VSIFOpenL(pszFilename, "r"); - if (fp == nullptr) - return FALSE; - - eValidity = SVG_VALIDITY_UNKNOWN; - - XML_Parser oParser = OGRCreateExpatXMLParser(); - oCurrentParser = oParser; - XML_SetUserData(oParser, this); - XML_SetElementHandler(oParser, ::startElementValidateCbk, nullptr); - XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk); - - std::vector aBuf(PARSER_BUF_SIZE); - int nDone = 0; - unsigned int nLen = 0; - int nCount = 0; - - /* Begin to parse the file and look for the element */ - /* It *MUST* be the first element of an XML file */ - /* So once we have read the first element, we know if we can */ - /* handle the file or not with that driver */ - do - { - nDataHandlerCounter = 0; - nLen = (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fp); - nDone = nLen < aBuf.size(); - if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) - { - if (nLen <= PARSER_BUF_SIZE - 1) - aBuf[nLen] = 0; - else - aBuf[PARSER_BUF_SIZE - 1] = 0; - if (strstr(aBuf.data(), " 0); - - XML_ParserFree(oParser); - - VSIFCloseL(fp); - - if (eValidity == SVG_VALIDITY_VALID) - { - if (bIsCloudmade) - { - nLayers = 3; - papoLayers = (OGRSVGLayer **)CPLRealloc( - papoLayers, nLayers * sizeof(OGRSVGLayer *)); - papoLayers[0] = - new OGRSVGLayer(pszFilename, "points", SVG_POINTS, this); - papoLayers[1] = - new OGRSVGLayer(pszFilename, "lines", SVG_LINES, this); - papoLayers[2] = - new OGRSVGLayer(pszFilename, "polygons", SVG_POLYGONS, this); - } - else - { - CPLDebug( - "SVG", - "%s seems to be a SVG file, but not a Cloudmade vector one.", - pszFilename); - } - } - - return nLayers > 0; -#else - char aBuf[256]; - VSILFILE *fp = VSIFOpenL(pszFilename, "r"); - if (fp) - { - unsigned int nLen = (unsigned int)VSIFReadL(aBuf, 1, 255, fp); - aBuf[nLen] = 0; - if (strstr(aBuf, " - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "ogr_svg.h" -#include "cpl_conv.h" - -CPL_C_START -void RegisterOGRSVG(); -CPL_C_END - -// g++ -g -Wall -fPIC ogr/ogrsf_frmts/svg/*.c* -shared -o ogr_SVG.so -Iport -// -Igcore -Iogr -Iogr/ogrsf_frmts -Iogr/ogrsf_frmts/svg -L. -lgdal -DHAVE_EXPAT - -/************************************************************************/ -/* Open() */ -/************************************************************************/ - -static GDALDataset *OGRSVGDriverOpen(GDALOpenInfo *poOpenInfo) - -{ - if (poOpenInfo->eAccess == GA_Update || poOpenInfo->fpL == nullptr) - return nullptr; - - if (strstr((const char *)poOpenInfo->pabyHeader, "Open(poOpenInfo->pszFilename)) - { - delete poDS; - poDS = nullptr; - } - - return poDS; -} - -/************************************************************************/ -/* RegisterOGRSVG() */ -/************************************************************************/ - -void RegisterOGRSVG() - -{ - if (!GDAL_CHECK_VERSION("OGR/SVG driver")) - return; - - if (GDALGetDriverByName("SVG") != nullptr) - return; - - GDALDriver *poDriver = new GDALDriver(); - - poDriver->SetDescription("SVG"); - poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); - poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Scalable Vector Graphics"); - poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "svg"); - poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/svg.html"); - poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); - - poDriver->pfnOpen = OGRSVGDriverOpen; - - GetGDALDriverManager()->RegisterDriver(poDriver); -} diff --git a/ogr/ogrsf_frmts/svg/ogrsvglayer.cpp b/ogr/ogrsf_frmts/svg/ogrsvglayer.cpp deleted file mode 100644 index af82ae2645cc..000000000000 --- a/ogr/ogrsf_frmts/svg/ogrsvglayer.cpp +++ /dev/null @@ -1,843 +0,0 @@ -/****************************************************************************** - * - * Project: SVG Translator - * Purpose: Implements OGRSVGLayer class. - * Author: Even Rouault, even dot rouault at spatialys.com - * - ****************************************************************************** - * Copyright (c) 2011-2013, Even Rouault - * - * SPDX-License-Identifier: MIT - ****************************************************************************/ - -#include "ogr_svg.h" -#include "cpl_conv.h" - -/************************************************************************/ -/* OGRSVGLayer() */ -/************************************************************************/ - -OGRSVGLayer::OGRSVGLayer(const char *pszFilename, const char *pszLayerName, - SVGGeometryType svgGeomTypeIn, -#ifndef HAVE_EXPAT - CPL_UNUSED -#endif - OGRSVGDataSource *poDSIn) - : poFeatureDefn(nullptr), poSRS(nullptr), -#ifdef HAVE_EXPAT - poDS(poDSIn), -#endif - osLayerName(pszLayerName), svgGeomType(svgGeomTypeIn), nTotalFeatures(0), - nNextFID(0), fpSVG(nullptr), -#ifdef HAVE_EXPAT - oParser(nullptr), oSchemaParser(nullptr), -#endif - pszSubElementValue(nullptr), nSubElementValueLen(0), iCurrentField(0), - poFeature(nullptr), ppoFeatureTab(nullptr), nFeatureTabLength(0), - nFeatureTabIndex(0), depthLevel(0), interestingDepthLevel(0), - inInterestingElement(false), bStopParsing(false) -#ifdef HAVE_EXPAT - , - nWithoutEventCounter(0), nDataHandlerCounter(0), poCurLayer(nullptr) -#endif - -{ - SetDescription(pszLayerName); - - poSRS = new OGRSpatialReference( - "PROJCS[\"WGS 84 / Pseudo-Mercator\"," - "GEOGCS[\"WGS 84\"," - " DATUM[\"WGS_1984\"," - " SPHEROID[\"WGS 84\",6378137,298.257223563," - " AUTHORITY[\"EPSG\",\"7030\"]]," - " AUTHORITY[\"EPSG\",\"6326\"]]," - " PRIMEM[\"Greenwich\",0," - " AUTHORITY[\"EPSG\",\"8901\"]]," - " UNIT[\"degree\",0.0174532925199433," - " AUTHORITY[\"EPSG\",\"9122\"]]," - " AUTHORITY[\"EPSG\",\"4326\"]]," - "UNIT[\"metre\",1," - " AUTHORITY[\"EPSG\",\"9001\"]]," - "PROJECTION[\"Mercator_1SP\"]," - "PARAMETER[\"central_meridian\",0]," - "PARAMETER[\"scale_factor\",1]," - "PARAMETER[\"false_easting\",0]," - "PARAMETER[\"false_northing\",0]," - "EXTENSION[\"PROJ4\",\"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 " - "+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext " - "+no_defs\"]," - "AUTHORITY[\"EPSG\",\"3857\"]," - "AXIS[\"X\",EAST]," - "AXIS[\"Y\",NORTH]]"); - poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); - - fpSVG = VSIFOpenL(pszFilename, "r"); - if (fpSVG == nullptr) - { - CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", pszFilename); - return; - } - - OGRSVGLayer::ResetReading(); -} - -/************************************************************************/ -/* ~OGRSVGLayer() */ -/************************************************************************/ - -OGRSVGLayer::~OGRSVGLayer() - -{ -#ifdef HAVE_EXPAT - if (oParser) - XML_ParserFree(oParser); -#endif - if (poFeatureDefn) - poFeatureDefn->Release(); - - if (poSRS != nullptr) - poSRS->Release(); - - CPLFree(pszSubElementValue); - - for (int i = nFeatureTabIndex; i < nFeatureTabLength; i++) - delete ppoFeatureTab[i]; - CPLFree(ppoFeatureTab); - - if (poFeature) - delete poFeature; - - if (fpSVG) - VSIFCloseL(fpSVG); -} - -#ifdef HAVE_EXPAT - -static void XMLCALL startElementCbk(void *pUserData, const char *pszName, - const char **ppszAttr) -{ - ((OGRSVGLayer *)pUserData)->startElementCbk(pszName, ppszAttr); -} - -static void XMLCALL endElementCbk(void *pUserData, const char *pszName) -{ - ((OGRSVGLayer *)pUserData)->endElementCbk(pszName); -} - -static void XMLCALL dataHandlerCbk(void *pUserData, const char *data, int nLen) -{ - ((OGRSVGLayer *)pUserData)->dataHandlerCbk(data, nLen); -} - -#endif - -/************************************************************************/ -/* ResetReading() */ -/************************************************************************/ - -void OGRSVGLayer::ResetReading() - -{ - nNextFID = 0; - if (fpSVG) - { - VSIFSeekL(fpSVG, 0, SEEK_SET); - VSIFClearErrL(fpSVG); -#ifdef HAVE_EXPAT - if (oParser) - XML_ParserFree(oParser); - - oParser = OGRCreateExpatXMLParser(); - XML_SetElementHandler(oParser, ::startElementCbk, ::endElementCbk); - XML_SetCharacterDataHandler(oParser, ::dataHandlerCbk); - XML_SetUserData(oParser, this); -#endif - } - - CPLFree(pszSubElementValue); - pszSubElementValue = nullptr; - nSubElementValueLen = 0; - iCurrentField = -1; - - for (int i = nFeatureTabIndex; i < nFeatureTabLength; i++) - delete ppoFeatureTab[i]; - CPLFree(ppoFeatureTab); - nFeatureTabIndex = 0; - nFeatureTabLength = 0; - ppoFeatureTab = nullptr; - if (poFeature) - delete poFeature; - poFeature = nullptr; - - depthLevel = 0; - interestingDepthLevel = 0; - inInterestingElement = false; -} - -#ifdef HAVE_EXPAT - -/************************************************************************/ -/* OGRSVGGetClass() */ -/************************************************************************/ - -static const char *OGRSVGGetClass(const char **ppszAttr) -{ - const char **ppszIter = ppszAttr; - while (*ppszIter) - { - if (strcmp(ppszIter[0], "class") == 0) - return ppszIter[1]; - ppszIter += 2; - } - return ""; -} - -/************************************************************************/ -/* OGRSVGParseD() */ -/************************************************************************/ - -static void OGRSVGParseD(OGRLineString *poLS, const char *pszD) -{ - char szBuffer[32]; - int iBuffer = 0; - const char *pszIter = pszD; - int iNumber = 0; - double dfPrevNumber = 0.0; - bool bRelativeLineto = false; - double dfX = 0.0; - double dfY = 0.0; - int nPointCount = 0; - while (true) - { - const char ch = *(pszIter++); - - if (ch == 'M' || ch == 'm') - { - if (nPointCount != 0) - { - CPLDebug("SVG", "Not ready to handle M/m not at the beginning"); - return; - } - } - else if (ch == 'L') - { - bRelativeLineto = false; - } - else if (ch == 'l') - { - if (nPointCount == 0) - { - CPLDebug("SVG", "Relative lineto at the beginning of the line"); - return; - } - bRelativeLineto = true; - } - else if (ch == 'z' || ch == 'Z') - { - poLS->closeRings(); - return; - } - else if (ch == '+' || ch == '-' || ch == '.' || - (ch >= '0' && ch <= '9')) - { - if (iBuffer == 30) - { - CPLDebug("SVG", "Too big number"); - return; - } - szBuffer[iBuffer++] = ch; - } - else if (ch == ' ' || ch == 0) - { - if (iBuffer > 0) - { - szBuffer[iBuffer] = 0; - if (iNumber == 1) - { - // Cloudmade --> negate y. - const double dfNumber = -CPLAtof(szBuffer); - - if (bRelativeLineto) - { - dfX += dfPrevNumber; - dfY += dfNumber; - } - else - { - dfX = dfPrevNumber; - dfY = dfNumber; - } - poLS->addPoint(dfX, dfY); - nPointCount++; - - iNumber = 0; - } - else - { - iNumber = 1; - dfPrevNumber = CPLAtof(szBuffer); - } - - iBuffer = 0; - } - if (ch == 0) - break; - } - } -} - -/************************************************************************/ -/* startElementCbk() */ -/************************************************************************/ - -void OGRSVGLayer::startElementCbk(const char *pszName, const char **ppszAttr) -{ - if (bStopParsing) - return; - - nWithoutEventCounter = 0; - - if (svgGeomType == SVG_POINTS && strcmp(pszName, "circle") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "point") == 0) - { - bool bHasFoundX = false; - bool bHasFoundY = false; - double dfX = 0.0; - double dfY = 0.0; - for (int i = 0; ppszAttr[i]; i += 2) - { - if (strcmp(ppszAttr[i], "cx") == 0) - { - bHasFoundX = true; - dfX = CPLAtof(ppszAttr[i + 1]); - } - else if (strcmp(ppszAttr[i], "cy") == 0) - { - bHasFoundY = true; - /* Cloudmade --> negate y */ - dfY = -CPLAtof(ppszAttr[i + 1]); - } - } - if (bHasFoundX && bHasFoundY) - { - interestingDepthLevel = depthLevel; - inInterestingElement = true; - - if (poFeature) - delete poFeature; - - poFeature = new OGRFeature(poFeatureDefn); - - poFeature->SetFID(nNextFID++); - OGRPoint *poPoint = new OGRPoint(dfX, dfY); - poPoint->assignSpatialReference(poSRS); - poFeature->SetGeometryDirectly(poPoint); - } - } - else if (svgGeomType == SVG_LINES && strcmp(pszName, "path") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "line") == 0) - { - const char *pszD = nullptr; - for (int i = 0; ppszAttr[i]; i += 2) - { - if (strcmp(ppszAttr[i], "d") == 0) - { - pszD = ppszAttr[i + 1]; - break; - } - } - if (pszD) - { - interestingDepthLevel = depthLevel; - inInterestingElement = true; - - if (poFeature) - delete poFeature; - - poFeature = new OGRFeature(poFeatureDefn); - - poFeature->SetFID(nNextFID++); - OGRLineString *poLS = new OGRLineString(); - OGRSVGParseD(poLS, pszD); - poLS->assignSpatialReference(poSRS); - poFeature->SetGeometryDirectly(poLS); - } - } - else if (svgGeomType == SVG_POLYGONS && strcmp(pszName, "path") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "polygon") == 0) - { - const char *pszD = nullptr; - for (int i = 0; ppszAttr[i]; i += 2) - { - if (strcmp(ppszAttr[i], "d") == 0) - { - pszD = ppszAttr[i + 1]; - break; - } - } - if (pszD) - { - interestingDepthLevel = depthLevel; - inInterestingElement = true; - - if (poFeature) - delete poFeature; - - poFeature = new OGRFeature(poFeatureDefn); - - poFeature->SetFID(nNextFID++); - OGRPolygon *poPolygon = new OGRPolygon(); - OGRLinearRing *poLS = new OGRLinearRing(); - OGRSVGParseD(poLS, pszD); - poPolygon->addRingDirectly(poLS); - poPolygon->assignSpatialReference(poSRS); - poFeature->SetGeometryDirectly(poPolygon); - } - } - else if (inInterestingElement && depthLevel == interestingDepthLevel + 1 && - STARTS_WITH(pszName, "cm:")) - { - iCurrentField = poFeatureDefn->GetFieldIndex(pszName + 3); - } - - depthLevel++; -} - -/************************************************************************/ -/* endElementCbk() */ -/************************************************************************/ - -void OGRSVGLayer::endElementCbk(CPL_UNUSED const char *pszName) -{ - if (bStopParsing) - return; - - nWithoutEventCounter = 0; - - depthLevel--; - - if (inInterestingElement) - { - if (depthLevel == interestingDepthLevel) - { - inInterestingElement = false; - - if ((m_poFilterGeom == nullptr || - FilterGeometry(poFeature->GetGeometryRef())) && - (m_poAttrQuery == nullptr || - m_poAttrQuery->Evaluate(poFeature))) - { - ppoFeatureTab = (OGRFeature **)CPLRealloc( - ppoFeatureTab, - sizeof(OGRFeature *) * (nFeatureTabLength + 1)); - ppoFeatureTab[nFeatureTabLength] = poFeature; - nFeatureTabLength++; - } - else - { - delete poFeature; - } - poFeature = nullptr; - } - else if (depthLevel == interestingDepthLevel + 1) - { - if (poFeature && iCurrentField >= 0 && nSubElementValueLen) - { - pszSubElementValue[nSubElementValueLen] = 0; - poFeature->SetField(iCurrentField, pszSubElementValue); - } - - CPLFree(pszSubElementValue); - pszSubElementValue = nullptr; - nSubElementValueLen = 0; - iCurrentField = -1; - } - } -} - -/************************************************************************/ -/* dataHandlerCbk() */ -/************************************************************************/ - -void OGRSVGLayer::dataHandlerCbk(const char *data, int nLen) -{ - if (bStopParsing) - return; - - nDataHandlerCounter++; - if (nDataHandlerCounter >= PARSER_BUF_SIZE) - { - CPLError(CE_Failure, CPLE_AppDefined, - "File probably corrupted (million laugh pattern)"); - XML_StopParser(oParser, XML_FALSE); - bStopParsing = true; - return; - } - - nWithoutEventCounter = 0; - - if (iCurrentField >= 0) - { - char *pszNewSubElementValue = (char *)VSI_REALLOC_VERBOSE( - pszSubElementValue, nSubElementValueLen + nLen + 1); - if (pszNewSubElementValue == nullptr) - { - XML_StopParser(oParser, XML_FALSE); - bStopParsing = true; - return; - } - pszSubElementValue = pszNewSubElementValue; - memcpy(pszSubElementValue + nSubElementValueLen, data, nLen); - nSubElementValueLen += nLen; - if (nSubElementValueLen > 100000) - { - CPLError( - CE_Failure, CPLE_AppDefined, - "Too much data inside one element. File probably corrupted"); - XML_StopParser(oParser, XML_FALSE); - bStopParsing = true; - } - } -} -#endif - -/************************************************************************/ -/* GetNextFeature() */ -/************************************************************************/ - -OGRFeature *OGRSVGLayer::GetNextFeature() -{ - GetLayerDefn(); - - if (fpSVG == nullptr) - return nullptr; - - if (bStopParsing) - return nullptr; - -#ifdef HAVE_EXPAT - if (nFeatureTabIndex < nFeatureTabLength) - { - return ppoFeatureTab[nFeatureTabIndex++]; - } - - if (VSIFEofL(fpSVG) || VSIFErrorL(fpSVG)) - return nullptr; - - std::vector aBuf(PARSER_BUF_SIZE); - - CPLFree(ppoFeatureTab); - ppoFeatureTab = nullptr; - nFeatureTabLength = 0; - nFeatureTabIndex = 0; - nWithoutEventCounter = 0; - iCurrentField = -1; - - int nDone = 0; - do - { - nDataHandlerCounter = 0; - unsigned int nLen = - (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpSVG); - nDone = nLen < aBuf.size(); - if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) - { - CPLError( - CE_Failure, CPLE_AppDefined, - "XML parsing of SVG file failed : %s at line %d, column %d", - XML_ErrorString(XML_GetErrorCode(oParser)), - (int)XML_GetCurrentLineNumber(oParser), - (int)XML_GetCurrentColumnNumber(oParser)); - bStopParsing = true; - break; - } - nWithoutEventCounter++; - } while (!nDone && nFeatureTabLength == 0 && !bStopParsing && - nWithoutEventCounter < 1000); - - if (nWithoutEventCounter == 1000) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Too much data inside one element. File probably corrupted"); - bStopParsing = true; - } - - return (nFeatureTabLength) ? ppoFeatureTab[nFeatureTabIndex++] : nullptr; -#else - return nullptr; -#endif -} - -/************************************************************************/ -/* TestCapability() */ -/************************************************************************/ - -int OGRSVGLayer::TestCapability(const char *pszCap) - -{ - if (EQUAL(pszCap, OLCFastFeatureCount)) - return m_poAttrQuery == nullptr && m_poFilterGeom == nullptr && - nTotalFeatures > 0; - - else if (EQUAL(pszCap, OLCStringsAsUTF8)) - return TRUE; - - else - return FALSE; -} - -/************************************************************************/ -/* LoadSchema() */ -/************************************************************************/ - -#ifdef HAVE_EXPAT - -static void XMLCALL startElementLoadSchemaCbk(void *pUserData, - const char *pszName, - const char **ppszAttr) -{ - ((OGRSVGLayer *)pUserData)->startElementLoadSchemaCbk(pszName, ppszAttr); -} - -static void XMLCALL endElementLoadSchemaCbk(void *pUserData, - const char *pszName) -{ - ((OGRSVGLayer *)pUserData)->endElementLoadSchemaCbk(pszName); -} - -static void XMLCALL dataHandlerLoadSchemaCbk(void *pUserData, const char *data, - int nLen) -{ - ((OGRSVGLayer *)pUserData)->dataHandlerLoadSchemaCbk(data, nLen); -} - -/** This function parses the whole file to build the schema */ -void OGRSVGLayer::LoadSchema() -{ - CPLAssert(poFeatureDefn == nullptr); - - for (int i = 0; i < poDS->GetLayerCount(); i++) - { - OGRSVGLayer *poLayer = (OGRSVGLayer *)poDS->GetLayer(i); - poLayer->poFeatureDefn = new OGRFeatureDefn(poLayer->osLayerName); - poLayer->poFeatureDefn->Reference(); - poLayer->poFeatureDefn->SetGeomType(poLayer->GetGeomType()); - poLayer->poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef( - poLayer->poSRS); - } - - oSchemaParser = OGRCreateExpatXMLParser(); - XML_SetElementHandler(oSchemaParser, ::startElementLoadSchemaCbk, - ::endElementLoadSchemaCbk); - XML_SetCharacterDataHandler(oSchemaParser, ::dataHandlerLoadSchemaCbk); - XML_SetUserData(oSchemaParser, this); - - if (fpSVG == nullptr) - return; - - VSIFSeekL(fpSVG, 0, SEEK_SET); - - inInterestingElement = false; - depthLevel = 0; - nWithoutEventCounter = 0; - bStopParsing = false; - - std::vector aBuf(PARSER_BUF_SIZE); - int nDone = 0; - do - { - nDataHandlerCounter = 0; - unsigned int nLen = - (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpSVG); - nDone = nLen < aBuf.size(); - if (XML_Parse(oSchemaParser, aBuf.data(), nLen, nDone) == - XML_STATUS_ERROR) - { - CPLError( - CE_Failure, CPLE_AppDefined, - "XML parsing of SVG file failed : %s at line %d, column %d", - XML_ErrorString(XML_GetErrorCode(oSchemaParser)), - (int)XML_GetCurrentLineNumber(oSchemaParser), - (int)XML_GetCurrentColumnNumber(oSchemaParser)); - bStopParsing = true; - break; - } - nWithoutEventCounter++; - } while (!nDone && !bStopParsing && nWithoutEventCounter < 1000); - - if (nWithoutEventCounter == 1000) - { - CPLError(CE_Failure, CPLE_AppDefined, - "Too much data inside one element. File probably corrupted"); - bStopParsing = true; - } - - XML_ParserFree(oSchemaParser); - oSchemaParser = nullptr; - - VSIFSeekL(fpSVG, 0, SEEK_SET); -} - -/************************************************************************/ -/* startElementLoadSchemaCbk() */ -/************************************************************************/ - -void OGRSVGLayer::startElementLoadSchemaCbk(const char *pszName, - const char **ppszAttr) -{ - if (bStopParsing) - return; - - nWithoutEventCounter = 0; - - if (strcmp(pszName, "circle") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "point") == 0) - { - poCurLayer = cpl::down_cast(poDS->GetLayer(0)); - if (!poCurLayer) - { - CPLAssert(false); - return; - } - poCurLayer->nTotalFeatures++; - inInterestingElement = true; - interestingDepthLevel = depthLevel; - } - else if (strcmp(pszName, "path") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "line") == 0) - { - poCurLayer = cpl::down_cast(poDS->GetLayer(1)); - if (!poCurLayer) - { - CPLAssert(false); - return; - } - poCurLayer->nTotalFeatures++; - inInterestingElement = true; - interestingDepthLevel = depthLevel; - } - else if (strcmp(pszName, "path") == 0 && - strcmp(OGRSVGGetClass(ppszAttr), "polygon") == 0) - { - poCurLayer = cpl::down_cast(poDS->GetLayer(2)); - if (!poCurLayer) - { - CPLAssert(false); - return; - } - poCurLayer->nTotalFeatures++; - inInterestingElement = true; - interestingDepthLevel = depthLevel; - } - else if (inInterestingElement) - { - if (depthLevel == interestingDepthLevel + 1 && - STARTS_WITH(pszName, "cm:")) - { - pszName += 3; - if (poCurLayer->poFeatureDefn->GetFieldIndex(pszName) < 0) - { - OGRFieldDefn oFieldDefn(pszName, OFTString); - if (strcmp(pszName, "timestamp") == 0) - oFieldDefn.SetType(OFTDateTime); - else if (strcmp(pszName, "way_area") == 0 || - strcmp(pszName, "area") == 0) - oFieldDefn.SetType(OFTReal); - else if (strcmp(pszName, "z_order") == 0) - oFieldDefn.SetType(OFTInteger); - poCurLayer->poFeatureDefn->AddFieldDefn(&oFieldDefn); - } - } - } - - depthLevel++; -} - -/************************************************************************/ -/* endElementLoadSchemaCbk() */ -/************************************************************************/ - -void OGRSVGLayer::endElementLoadSchemaCbk(CPL_UNUSED const char *pszName) -{ - if (bStopParsing) - return; - - nWithoutEventCounter = 0; - - depthLevel--; - - if (inInterestingElement && depthLevel == interestingDepthLevel) - { - inInterestingElement = false; - } -} - -/************************************************************************/ -/* dataHandlerLoadSchemaCbk() */ -/************************************************************************/ - -void OGRSVGLayer::dataHandlerLoadSchemaCbk(CPL_UNUSED const char *data, - CPL_UNUSED int nLen) -{ - if (bStopParsing) - return; - - nDataHandlerCounter++; - if (nDataHandlerCounter >= PARSER_BUF_SIZE) - { - CPLError(CE_Failure, CPLE_AppDefined, - "File probably corrupted (million laugh pattern)"); - XML_StopParser(oSchemaParser, XML_FALSE); - bStopParsing = true; - return; - } - - nWithoutEventCounter = 0; -} -#else -void OGRSVGLayer::LoadSchema() -{ -} -#endif - -/************************************************************************/ -/* GetLayerDefn() */ -/************************************************************************/ - -OGRFeatureDefn *OGRSVGLayer::GetLayerDefn() -{ - if (poFeatureDefn == nullptr) - { - LoadSchema(); - } - - return poFeatureDefn; -} - -/************************************************************************/ -/* GetGeomType() */ -/************************************************************************/ - -OGRwkbGeometryType OGRSVGLayer::GetGeomType() -{ - if (svgGeomType == SVG_POINTS) - return wkbPoint; - else if (svgGeomType == SVG_LINES) - return wkbLineString; - else - return wkbPolygon; -} - -/************************************************************************/ -/* GetGeomType() */ -/************************************************************************/ - -GIntBig OGRSVGLayer::GetFeatureCount(int bForce) -{ - if (m_poAttrQuery != nullptr || m_poFilterGeom != nullptr) - return OGRLayer::GetFeatureCount(bForce); - - GetLayerDefn(); - - return nTotalFeatures; -}