GeoJSONSourceType GeoJSONGetSourceType( const char* pszSource ) { GeoJSONSourceType srcType = eGeoJSONSourceUnknown; // NOTE: Sometimes URL ends with .geojson token, for example // http://example/path/2232.geojson // It's important to test beginning of source first. if ( eGeoJSONProtocolUnknown != GeoJSONGetProtocolType( pszSource ) ) { srcType = eGeoJSONSourceService; } else if( EQUAL( CPLGetExtension( pszSource ), "geojson" ) || EQUAL( CPLGetExtension( pszSource ), "json" ) || ((EQUALN( pszSource, "/vsigzip/", 9) || EQUALN( pszSource, "/vsizip/", 8)) && (strstr( pszSource, ".json") || strstr( pszSource, ".JSON") || strstr( pszSource, ".geojson") || strstr( pszSource, ".GEOJSON")) )) { srcType = eGeoJSONSourceFile; } else if( GeoJSONIsObject( pszSource ) ) { srcType = eGeoJSONSourceText; } else if( GeoJSONFileIsObject( pszSource ) ) { srcType = eGeoJSONSourceFile; } return srcType; }
static int GeoJSONFileIsObject( GDALOpenInfo* poOpenInfo ) { // by default read first 6000 bytes // 6000 was chosen as enough bytes to // enable all current tests to pass if( poOpenInfo->fpL == NULL || !poOpenInfo->TryToIngest(6000) ) { return FALSE; } if( !GeoJSONIsObject((const char*)poOpenInfo->pabyHeader) ) { return FALSE; } return TRUE; }
static bool GeoJSONFileIsObject( GDALOpenInfo* poOpenInfo ) { // By default read first 6000 bytes. // 6000 was chosen as enough bytes to // enable all current tests to pass. if( poOpenInfo->fpL == NULL || !poOpenInfo->TryToIngest(6000) ) { return false; } if( !GeoJSONIsObject((const char*)poOpenInfo->pabyHeader) ) { return false; } return true; }
GeoJSONSourceType GeoJSONGetSourceType( GDALOpenInfo* poOpenInfo ) { GeoJSONSourceType srcType = eGeoJSONSourceUnknown; // NOTE: Sometimes URL ends with .geojson token, for example // http://example/path/2232.geojson // It's important to test beginning of source first. if( eGeoJSONProtocolUnknown != GeoJSONGetProtocolType( poOpenInfo->pszFilename ) ) { if( (strstr(poOpenInfo->pszFilename, "SERVICE=WFS") || strstr(poOpenInfo->pszFilename, "service=WFS") || strstr(poOpenInfo->pszFilename, "service=wfs")) && !strstr(poOpenInfo->pszFilename, "json") ) return srcType; srcType = eGeoJSONSourceService; } else if( EQUAL( CPLGetExtension( poOpenInfo->pszFilename ), "geojson" ) || EQUAL( CPLGetExtension( poOpenInfo->pszFilename ), "json" ) || EQUAL( CPLGetExtension( poOpenInfo->pszFilename ), "topojson" ) || ((STARTS_WITH_CI(poOpenInfo->pszFilename, "/vsigzip/") || STARTS_WITH_CI(poOpenInfo->pszFilename, "/vsizip/")) && (strstr( poOpenInfo->pszFilename, ".json") || strstr( poOpenInfo->pszFilename, ".JSON") || strstr( poOpenInfo->pszFilename, ".geojson") || strstr( poOpenInfo->pszFilename, ".GEOJSON")) )) { if( poOpenInfo->fpL != NULL ) srcType = eGeoJSONSourceFile; } else if( GeoJSONIsObject( poOpenInfo->pszFilename ) ) { srcType = eGeoJSONSourceText; } else if( GeoJSONFileIsObject( poOpenInfo ) ) { srcType = eGeoJSONSourceFile; } return srcType; }