/src/gdal/ogr/ogrsf_frmts/geojson/ogrtopojsondriver.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: OpenGIS Simple Features Reference Implementation |
4 | | * Purpose: TopoJSON driver |
5 | | * Author: Even Rouault, <even.rouault at spatialys.com> |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2017, Even Rouault, <even.rouault at spatialys.com> |
9 | | * |
10 | | * SPDX-License-Identifier: MIT |
11 | | ****************************************************************************/ |
12 | | |
13 | | #include "cpl_port.h" |
14 | | #include "ogr_geojson.h" |
15 | | |
16 | | #include <stdlib.h> |
17 | | #include <string.h> |
18 | | |
19 | | #include "cpl_conv.h" |
20 | | #include "cpl_error.h" |
21 | | #include "gdal.h" |
22 | | #include "gdal_priv.h" |
23 | | #include "ogrgeojsonutils.h" |
24 | | #include "ogrsf_frmts.h" |
25 | | |
26 | | /************************************************************************/ |
27 | | /* OGRTopoJSONDriverIdentify() */ |
28 | | /************************************************************************/ |
29 | | |
30 | | static int OGRTopoJSONDriverIdentify(GDALOpenInfo *poOpenInfo) |
31 | 0 | { |
32 | 0 | GeoJSONSourceType nSrcType = TopoJSONDriverGetSourceType(poOpenInfo); |
33 | 0 | if (nSrcType == eGeoJSONSourceUnknown) |
34 | 0 | return FALSE; |
35 | 0 | if (nSrcType == eGeoJSONSourceService) |
36 | 0 | { |
37 | 0 | if (poOpenInfo->IsSingleAllowedDriver("TopoJSON")) |
38 | 0 | return TRUE; |
39 | 0 | if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "TopoJSON:")) |
40 | 0 | { |
41 | 0 | return -1; |
42 | 0 | } |
43 | 0 | } |
44 | 0 | return TRUE; |
45 | 0 | } |
46 | | |
47 | | /************************************************************************/ |
48 | | /* Open() */ |
49 | | /************************************************************************/ |
50 | | |
51 | | static GDALDataset *OGRTopoJSONDriverOpen(GDALOpenInfo *poOpenInfo) |
52 | 0 | { |
53 | 0 | GeoJSONSourceType nSrcType = TopoJSONDriverGetSourceType(poOpenInfo); |
54 | 0 | if (nSrcType == eGeoJSONSourceUnknown) |
55 | 0 | return nullptr; |
56 | 0 | return OGRGeoJSONDriverOpenInternal(poOpenInfo, nSrcType, "TopoJSON"); |
57 | 0 | } |
58 | | |
59 | | /************************************************************************/ |
60 | | /* RegisterOGRTopoJSON() */ |
61 | | /************************************************************************/ |
62 | | |
63 | | void RegisterOGRTopoJSON() |
64 | 0 | { |
65 | 0 | if (!GDAL_CHECK_VERSION("OGR/TopoJSON driver")) |
66 | 0 | return; |
67 | | |
68 | 0 | if (GDALGetDriverByName("TopoJSON") != nullptr) |
69 | 0 | return; |
70 | | |
71 | 0 | GDALDriver *poDriver = new GDALDriver(); |
72 | |
|
73 | 0 | poDriver->SetDescription("TopoJSON"); |
74 | 0 | poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); |
75 | 0 | poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "TopoJSON"); |
76 | 0 | poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "json topojson"); |
77 | 0 | poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, |
78 | 0 | "drivers/vector/topojson.html"); |
79 | |
|
80 | 0 | poDriver->SetMetadataItem(GDAL_DMD_OPENOPTIONLIST, "<OpenOptionList/>"); |
81 | |
|
82 | 0 | poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST, |
83 | 0 | "<CreationOptionList/>"); |
84 | |
|
85 | 0 | poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); |
86 | |
|
87 | 0 | poDriver->pfnOpen = OGRTopoJSONDriverOpen; |
88 | 0 | poDriver->pfnIdentify = OGRTopoJSONDriverIdentify; |
89 | |
|
90 | 0 | GetGDALDriverManager()->RegisterDriver(poDriver); |
91 | 0 | } |