Package com.targomo.client.api.util
Class GeojsonUtil
java.lang.Object
com.targomo.client.api.util.GeojsonUtil
Utils for geojson. Currently supported methods:
- Transformation between geo formats
- Visualization of Geojson data in browser
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidopenGeoJsonInBrowserWithGeojsonIO(String gitHubUser, String githubTokenForGistUpload, Map<String, org.wololo.geojson.FeatureCollection> featureCollections) All filename-Featurepairs will be displayed in your default browser via the geojson.io website.static voidopenGeoJsonInBrowserWithGitHubGist(String gitHubUser, String githubTokenForGistUpload, Map<String, org.wololo.geojson.FeatureCollection> featureCollections) All filename-Featurepairs will be displayed in your default browser via the api.github.com/gists website.static List<org.wololo.geojson.Feature>transformGeometry(org.opengis.referencing.operation.MathTransform transformer, org.wololo.geojson.Feature... featuresToTransform) Transforms geojson geometry between different formats.
-
Method Details
-
transformGeometry
public static List<org.wololo.geojson.Feature> transformGeometry(org.opengis.referencing.operation.MathTransform transformer, org.wololo.geojson.Feature... featuresToTransform) throws org.opengis.referencing.operation.TransformException Transforms geojson geometry between different formats. Usage example:FeatureCollection featureCollectionIn3857 = ... //e.g. from the route service //Preparing transformer CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3857"); //Web Mercartor CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); //WGS84 MathTransform transformer = CRS.findMathTransform(sourceCRS, targetCRS); //Do transformation from EPSG:3857 (Web Mercartor) to EPSG:4326 (WGS84) FeatureCollection featureCollectionIn4326 = new FeatureCollection( GeojsonUtil.transformGeometry(featureCollectionIn3857,transformer).toArray(new Feature[0]));- Parameters:
transformer- transformer initialized with the correct formatsfeaturesToTransform- features that need to be transformed into the target format- Returns:
- Zero or more transformed geometry features
- Throws:
org.opengis.referencing.operation.TransformException- if the geographic projection transformation fails
-
openGeoJsonInBrowserWithGeojsonIO
public static void openGeoJsonInBrowserWithGeojsonIO(String gitHubUser, String githubTokenForGistUpload, Map<String, org.wololo.geojson.FeatureCollection> featureCollections) throws IOExceptionAll filename-Featurepairs will be displayed in your default browser via the geojson.io website. Requires connection to the internet. (Only EPSG:4326 (WGS84) mode tested)- Parameters:
gitHubUser- valid github account idgithubTokenForGistUpload- a token created for the user here: https://github.com/settings/tokens (must have gist creation scope)featureCollections- map of fileNames to their respective contents (i.e. theFeatureCollection)- Throws:
IOException- if errors during parsing or execution occurred
-
openGeoJsonInBrowserWithGitHubGist
public static void openGeoJsonInBrowserWithGitHubGist(String gitHubUser, String githubTokenForGistUpload, Map<String, org.wololo.geojson.FeatureCollection> featureCollections) throws IOExceptionAll filename-Featurepairs will be displayed in your default browser via the api.github.com/gists website. Requires connection to the internet. (Only EPSG:4326 (WGS84) mode tested) Has sometimes display errors - esp. if multiple FeatureCollections are to be shown in one page. In that case it is suggested to useopenGeoJsonInBrowserWithGeojsonIO(java.lang.String, java.lang.String, java.util.Map<java.lang.String, org.wololo.geojson.FeatureCollection>).- Parameters:
gitHubUser- valid github account idgithubTokenForGistUpload- a token created for the user here: https://github.com/settings/tokens (must have gist creation scope)featureCollections- map of fileNames and the respective contents (i.e. theFeatureCollection)- Throws:
IOException- if errors during parsing or execution occurred
-