Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implementation of OGC Features and Geometries JSON (JSON-FG) 5 : * Author: Even Rouault <even.rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, Even Rouault <even.rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "gdal_priv.h" 14 : #include "ogrsf_frmts.h" 15 : 16 : #include "ogr_jsonfg.h" 17 : #include "ogrgeojsonutils.h" 18 : 19 : /************************************************************************/ 20 : /* OGRJSONFGDriverIdentify() */ 21 : /************************************************************************/ 22 : 23 43032 : static int OGRJSONFGDriverIdentify(GDALOpenInfo *poOpenInfo) 24 : { 25 43032 : GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo); 26 43032 : if (nSrcType == eGeoJSONSourceUnknown) 27 42870 : return FALSE; 28 162 : if (nSrcType == eGeoJSONSourceService) 29 : { 30 18 : if (poOpenInfo->IsSingleAllowedDriver("JSONFG")) 31 1 : return TRUE; 32 17 : if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "JSONFG:")) 33 : { 34 17 : return -1; 35 : } 36 : } 37 144 : return TRUE; 38 : } 39 : 40 : /************************************************************************/ 41 : /* Open() */ 42 : /************************************************************************/ 43 : 44 151 : static GDALDataset *OGRJSONFGDriverOpen(GDALOpenInfo *poOpenInfo) 45 : { 46 151 : GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo); 47 151 : if (nSrcType == eGeoJSONSourceUnknown) 48 0 : return nullptr; 49 302 : auto poDS = std::make_unique<OGRJSONFGDataset>(); 50 151 : if (!poDS->Open(poOpenInfo, nSrcType)) 51 9 : return nullptr; 52 142 : return poDS.release(); 53 : } 54 : 55 : /************************************************************************/ 56 : /* Create() */ 57 : /************************************************************************/ 58 : 59 73 : static GDALDataset *OGRJSONFGDriverCreate(const char *pszName, int /* nBands */, 60 : int /* nXSize */, int /* nYSize */, 61 : GDALDataType /* eDT */, 62 : char **papszOptions) 63 : { 64 146 : auto poDS = std::make_unique<OGRJSONFGDataset>(); 65 73 : if (!poDS->Create(pszName, papszOptions)) 66 : { 67 1 : return nullptr; 68 : } 69 72 : return poDS.release(); 70 : } 71 : 72 : /************************************************************************/ 73 : /* RegisterOGRJSONFG() */ 74 : /************************************************************************/ 75 : 76 1595 : void RegisterOGRJSONFG() 77 : { 78 1595 : if (GDALGetDriverByName("JSONFG") != nullptr) 79 302 : return; 80 : 81 1293 : GDALDriver *poDriver = new GDALDriver(); 82 : 83 1293 : poDriver->SetDescription("JSONFG"); 84 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 85 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 86 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 87 1293 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 88 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 89 1293 : "OGC Features and Geometries JSON"); 90 1293 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "json"); 91 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/jsonfg.html"); 92 : 93 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 94 : 95 1293 : poDriver->SetMetadataItem( 96 : GDAL_DMD_OPENOPTIONLIST, 97 : "<OpenOptionList>" 98 : " <Option name='GEOMETRY_ELEMENT' type='string-select' " 99 : "description='Which JSON element to use to create geometry from'>" 100 : " <Value>AUTO</Value>" 101 : " <Value>PLACE</Value>" 102 : " <Value>GEOMETRY</Value>" 103 : " </Option>" 104 1293 : "</OpenOptionList>"); 105 : 106 1293 : poDriver->SetMetadataItem( 107 : GDAL_DMD_CREATIONOPTIONLIST, 108 : "<CreationOptionList>" 109 : " <Option name='SINGLE_LAYER' type='boolean' description='whether " 110 : "only one layer will be written' default='NO'/>" 111 1293 : "</CreationOptionList>"); 112 : 113 1293 : poDriver->SetMetadataItem( 114 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 115 : "<LayerCreationOptionList>" 116 : " <Option name='COORDINATE_PRECISION_GEOMETRY' type='int' " 117 : "description='Number of decimal for coordinates in the geometry " 118 : "element'/>" 119 : " <Option name='COORDINATE_PRECISION_PLACE' type='int' " 120 : "description='Number of decimal for coordinates in the place element'/>" 121 : " <Option name='WRITE_GEOMETRY' type='boolean' " 122 : "description='Can be set to NO to avoid writing the geometry element " 123 : "when place is written' default='YES'/>" 124 : " <Option name='SIGNIFICANT_FIGURES' type='int' description='Number " 125 : "of significant figures for floating-point values' default='17'/>" 126 : " <Option name='ID_FIELD' type='string' description='Name of the " 127 : "source field that must be used as the id member of Feature features'/>" 128 : " <Option name='ID_TYPE' type='string-select' description='Type of " 129 : "the id member of Feature features'>" 130 : " <Value>AUTO</Value>" 131 : " <Value>String</Value>" 132 : " <Value>Integer</Value>" 133 : " </Option>" 134 : " <Option name='ID_GENERATE' type='boolean' " 135 : "description='Auto-generate feature ids' default='NO'/>" 136 1293 : "</LayerCreationOptionList>"); 137 : 138 1293 : poDriver->SetMetadataItem( 139 : GDAL_DMD_CREATIONFIELDDATATYPES, 140 : "Integer Integer64 Real String IntegerList " 141 1293 : "Integer64List RealList StringList Date DateTime"); 142 1293 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, "Boolean"); 143 1293 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 144 1293 : poDriver->SetMetadataItem(GDAL_DCAP_FLUSHCACHE_CONSISTENT_STATE, "YES"); 145 1293 : poDriver->SetMetadataItem(GDAL_DCAP_HONOR_GEOM_COORDINATE_PRECISION, "YES"); 146 : 147 1293 : poDriver->pfnOpen = OGRJSONFGDriverOpen; 148 1293 : poDriver->pfnIdentify = OGRJSONFGDriverIdentify; 149 1293 : poDriver->pfnCreate = OGRJSONFGDriverCreate; 150 : 151 1293 : GetGDALDriverManager()->RegisterDriver(poDriver); 152 : }