本文整理匯總了Java中org.wololo.jts2geojson.GeoJSONWriter類的典型用法代碼示例。如果您正苦於以下問題:Java GeoJSONWriter類的具體用法?Java GeoJSONWriter怎麽用?Java GeoJSONWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GeoJSONWriter類屬於org.wololo.jts2geojson包,在下文中一共展示了GeoJSONWriter類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: geometryToGeoJson
import org.wololo.jts2geojson.GeoJSONWriter; //導入依賴的package包/類
public static ClobType geometryToGeoJson(GeometryType geometry)
throws FunctionExecutionException {
Geometry jtsGeometry = getGeometry(geometry);
GeoJSONWriter writer = new GeoJSONWriter();
try {
GeoJSON geoJson = writer.write(jtsGeometry);
ClobType result = new ClobType(new ClobImpl(geoJson.toString()));
result.setType(Type.JSON);
return result;
} catch (Exception e) {
throw new FunctionExecutionException(e);
}
}
示例2: transformGeometry
import org.wololo.jts2geojson.GeoJSONWriter; //導入依賴的package包/類
/**
* Transforms geojson geometry between different formats. Usage example:
* <pre>
* 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]));
* </pre>
*
* @param transformer transformer initialized with the correct formats
* @param featuresToTransform features that need to be transformed into the target format
* @return Zero or more transformed geometry features
* @throws TransformException if the geographic projection transformation fails
*/
public static List<Feature> transformGeometry(MathTransform transformer, Feature... featuresToTransform) throws TransformException {
List<Feature> featureList = new ArrayList<>(featuresToTransform.length);
for (Feature feature : featuresToTransform) {
GeoJSONReader reader = new GeoJSONReader();
Geometry geometry = reader.read(feature.getGeometry());
geometry = JTS.transform(geometry, transformer);
GeoJSONWriter writer = new GeoJSONWriter();
org.wololo.geojson.Geometry json = writer.write(geometry);
featureList.add(new Feature(json, feature.getProperties()));
}
return featureList;
}