@Test public void testParseCRSNameURI() throws Exception { JSONObject crsJSON = new JSONObject("{\"crs\":{\n" + " \"type\":\"name\",\n" + " \"properties\" : {\n" + " \"name\":\"urn:ogc:def:crs:EPSG::4326\"\n" + " }\n" + "}}"); CoordinateReferenceSystem crs = FeaturesParser.parseCoordinateReferenceSystem(this.requestFactory, crsJSON, false); assertNotNull(crs); assertEquals("EPSG:4326", CRS.lookupIdentifier(crs, false)); }
@VisibleForTesting static final CoordinateReferenceSystem parseCoordinateReferenceSystem( final MfClientHttpRequestFactory requestFactory, final JSONObject geojson, final boolean forceLongitudeFirst) { CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; StringBuilder code = new StringBuilder(); try { if (geojson.has("crs")) { JSONObject crsJson = geojson.getJSONObject("crs"); String type = crsJson.optString("type", ""); if (type.equalsIgnoreCase("EPSG") || type.equalsIgnoreCase("CRS")) { code.append(type); String propCode = getProperty(crsJson, "code"); if (propCode != null) { code.append(":").append(propCode); } } else if (type.equalsIgnoreCase("name")) { String propCode = getProperty(crsJson, "name"); if (propCode != null) { code.append(propCode); } } else if (type.equals("link")) { String linkType = getProperty(crsJson, "type"); if (linkType != null && (linkType.equalsIgnoreCase("esriwkt") || linkType.equalsIgnoreCase("ogcwkt"))) { String uri = getProperty(crsJson, "href"); if (uri != null) { ClientHttpRequest request = requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { if (response.getStatusCode() == HttpStatus.OK) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { return CRS.parseWKT(wkt); } catch (FactoryException e) { LOGGER.warn( "Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}", crsJson, wkt); } } } } } else { LOGGER.warn("Unable to load linked CRS from geojson: \n{}", crsJson); } } else { code.append(getProperty(crsJson, "code")); } } } catch (JSONException | IOException | URISyntaxException e) { LOGGER.warn("Error reading the required elements to parse crs of the geojson: \n{}", geojson, e); } try { if (code.length() > 0) { crs = CRS.decode(code.toString(), forceLongitudeFirst); } } catch (NoSuchAuthorityCodeException e) { LOGGER.warn("No CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } catch (FactoryException e) { LOGGER.warn("Error loading CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } return crs; }
FeaturesParser { @VisibleForTesting static final CoordinateReferenceSystem parseCoordinateReferenceSystem( final MfClientHttpRequestFactory requestFactory, final JSONObject geojson, final boolean forceLongitudeFirst) { CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; StringBuilder code = new StringBuilder(); try { if (geojson.has("crs")) { JSONObject crsJson = geojson.getJSONObject("crs"); String type = crsJson.optString("type", ""); if (type.equalsIgnoreCase("EPSG") || type.equalsIgnoreCase("CRS")) { code.append(type); String propCode = getProperty(crsJson, "code"); if (propCode != null) { code.append(":").append(propCode); } } else if (type.equalsIgnoreCase("name")) { String propCode = getProperty(crsJson, "name"); if (propCode != null) { code.append(propCode); } } else if (type.equals("link")) { String linkType = getProperty(crsJson, "type"); if (linkType != null && (linkType.equalsIgnoreCase("esriwkt") || linkType.equalsIgnoreCase("ogcwkt"))) { String uri = getProperty(crsJson, "href"); if (uri != null) { ClientHttpRequest request = requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { if (response.getStatusCode() == HttpStatus.OK) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { return CRS.parseWKT(wkt); } catch (FactoryException e) { LOGGER.warn( "Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}", crsJson, wkt); } } } } } else { LOGGER.warn("Unable to load linked CRS from geojson: \n{}", crsJson); } } else { code.append(getProperty(crsJson, "code")); } } } catch (JSONException | IOException | URISyntaxException e) { LOGGER.warn("Error reading the required elements to parse crs of the geojson: \n{}", geojson, e); } try { if (code.length() > 0) { crs = CRS.decode(code.toString(), forceLongitudeFirst); } } catch (NoSuchAuthorityCodeException e) { LOGGER.warn("No CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } catch (FactoryException e) { LOGGER.warn("Error loading CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } return crs; } }
FeaturesParser { @VisibleForTesting static final CoordinateReferenceSystem parseCoordinateReferenceSystem( final MfClientHttpRequestFactory requestFactory, final JSONObject geojson, final boolean forceLongitudeFirst) { CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; StringBuilder code = new StringBuilder(); try { if (geojson.has("crs")) { JSONObject crsJson = geojson.getJSONObject("crs"); String type = crsJson.optString("type", ""); if (type.equalsIgnoreCase("EPSG") || type.equalsIgnoreCase("CRS")) { code.append(type); String propCode = getProperty(crsJson, "code"); if (propCode != null) { code.append(":").append(propCode); } } else if (type.equalsIgnoreCase("name")) { String propCode = getProperty(crsJson, "name"); if (propCode != null) { code.append(propCode); } } else if (type.equals("link")) { String linkType = getProperty(crsJson, "type"); if (linkType != null && (linkType.equalsIgnoreCase("esriwkt") || linkType.equalsIgnoreCase("ogcwkt"))) { String uri = getProperty(crsJson, "href"); if (uri != null) { ClientHttpRequest request = requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { if (response.getStatusCode() == HttpStatus.OK) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { return CRS.parseWKT(wkt); } catch (FactoryException e) { LOGGER.warn( "Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}", crsJson, wkt); } } } } } else { LOGGER.warn("Unable to load linked CRS from geojson: \n{}", crsJson); } } else { code.append(getProperty(crsJson, "code")); } } } catch (JSONException | IOException | URISyntaxException e) { LOGGER.warn("Error reading the required elements to parse crs of the geojson: \n{}", geojson, e); } try { if (code.length() > 0) { crs = CRS.decode(code.toString(), forceLongitudeFirst); } } catch (NoSuchAuthorityCodeException e) { LOGGER.warn("No CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } catch (FactoryException e) { LOGGER.warn("Error loading CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } return crs; } FeaturesParser(
            final MfClientHttpRequestFactory httpRequestFactory, final boolean forceLongitudeFirst); }
FeaturesParser { @VisibleForTesting static final CoordinateReferenceSystem parseCoordinateReferenceSystem( final MfClientHttpRequestFactory requestFactory, final JSONObject geojson, final boolean forceLongitudeFirst) { CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; StringBuilder code = new StringBuilder(); try { if (geojson.has("crs")) { JSONObject crsJson = geojson.getJSONObject("crs"); String type = crsJson.optString("type", ""); if (type.equalsIgnoreCase("EPSG") || type.equalsIgnoreCase("CRS")) { code.append(type); String propCode = getProperty(crsJson, "code"); if (propCode != null) { code.append(":").append(propCode); } } else if (type.equalsIgnoreCase("name")) { String propCode = getProperty(crsJson, "name"); if (propCode != null) { code.append(propCode); } } else if (type.equals("link")) { String linkType = getProperty(crsJson, "type"); if (linkType != null && (linkType.equalsIgnoreCase("esriwkt") || linkType.equalsIgnoreCase("ogcwkt"))) { String uri = getProperty(crsJson, "href"); if (uri != null) { ClientHttpRequest request = requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { if (response.getStatusCode() == HttpStatus.OK) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { return CRS.parseWKT(wkt); } catch (FactoryException e) { LOGGER.warn( "Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}", crsJson, wkt); } } } } } else { LOGGER.warn("Unable to load linked CRS from geojson: \n{}", crsJson); } } else { code.append(getProperty(crsJson, "code")); } } } catch (JSONException | IOException | URISyntaxException e) { LOGGER.warn("Error reading the required elements to parse crs of the geojson: \n{}", geojson, e); } try { if (code.length() > 0) { crs = CRS.decode(code.toString(), forceLongitudeFirst); } } catch (NoSuchAuthorityCodeException e) { LOGGER.warn("No CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } catch (FactoryException e) { LOGGER.warn("Error loading CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } return crs; } FeaturesParser(
            final MfClientHttpRequestFactory httpRequestFactory, final boolean forceLongitudeFirst); final SimpleFeatureCollection autoTreat(final Template template, final String features); final SimpleFeatureCollection treatStringAsURL(final Template template, final String geoJsonUrl); final SimpleFeatureCollection treatStringAsGeoJson(final String geoJsonString); }
FeaturesParser { @VisibleForTesting static final CoordinateReferenceSystem parseCoordinateReferenceSystem( final MfClientHttpRequestFactory requestFactory, final JSONObject geojson, final boolean forceLongitudeFirst) { CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; StringBuilder code = new StringBuilder(); try { if (geojson.has("crs")) { JSONObject crsJson = geojson.getJSONObject("crs"); String type = crsJson.optString("type", ""); if (type.equalsIgnoreCase("EPSG") || type.equalsIgnoreCase("CRS")) { code.append(type); String propCode = getProperty(crsJson, "code"); if (propCode != null) { code.append(":").append(propCode); } } else if (type.equalsIgnoreCase("name")) { String propCode = getProperty(crsJson, "name"); if (propCode != null) { code.append(propCode); } } else if (type.equals("link")) { String linkType = getProperty(crsJson, "type"); if (linkType != null && (linkType.equalsIgnoreCase("esriwkt") || linkType.equalsIgnoreCase("ogcwkt"))) { String uri = getProperty(crsJson, "href"); if (uri != null) { ClientHttpRequest request = requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { if (response.getStatusCode() == HttpStatus.OK) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { return CRS.parseWKT(wkt); } catch (FactoryException e) { LOGGER.warn( "Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}", crsJson, wkt); } } } } } else { LOGGER.warn("Unable to load linked CRS from geojson: \n{}", crsJson); } } else { code.append(getProperty(crsJson, "code")); } } } catch (JSONException | IOException | URISyntaxException e) { LOGGER.warn("Error reading the required elements to parse crs of the geojson: \n{}", geojson, e); } try { if (code.length() > 0) { crs = CRS.decode(code.toString(), forceLongitudeFirst); } } catch (NoSuchAuthorityCodeException e) { LOGGER.warn("No CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } catch (FactoryException e) { LOGGER.warn("Error loading CRS with code: {}.\nRead from geojson: \n{}", code, geojson); } return crs; } FeaturesParser(
            final MfClientHttpRequestFactory httpRequestFactory, final boolean forceLongitudeFirst); final SimpleFeatureCollection autoTreat(final Template template, final String features); final SimpleFeatureCollection treatStringAsURL(final Template template, final String geoJsonUrl); final SimpleFeatureCollection treatStringAsGeoJson(final String geoJsonString);  }