11/*
2- Copyright 1995-2015 Esri
2+ Copyright 1995-2017 Esri
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
2929import java .nio .ByteOrder ;
3030import java .util .ArrayList ;
3131
32- import org .codehaus .jackson .JsonParseException ;
33- import org .codehaus .jackson .JsonParser ;
34- import org .json .JSONException ;
32+ import com .fasterxml .jackson .core .JsonParser ;
3533
3634/**
3735 * Provides services that operate on geometry instances. The methods of GeometryEngine class call corresponding OperatorXXX classes.
@@ -57,10 +55,27 @@ public class GeometryEngine {
5755 * spatial reference.
5856 */
5957 public static MapGeometry jsonToGeometry (JsonParser json ) {
60- MapGeometry geom = OperatorImportFromJson .local ().execute (Geometry .Type .Unknown , json );
58+ MapGeometry geom = OperatorImportFromJson .local ().execute (Geometry .Type .Unknown , new JsonParserReader ( json ) );
6159 return geom ;
6260 }
6361
62+ /**
63+ * Imports the MapGeometry from its JSON representation. M and Z values are
64+ * not imported from JSON representation.
65+ *
66+ * See OperatorImportFromJson.
67+ *
68+ * @param json
69+ * The JSON representation of the geometry (with spatial
70+ * reference).
71+ * @return The MapGeometry instance containing the imported geometry and its
72+ * spatial reference.
73+ */
74+ public static MapGeometry jsonToGeometry (JsonReader json ) {
75+ MapGeometry geom = OperatorImportFromJson .local ().execute (Geometry .Type .Unknown , json );
76+ return geom ;
77+ }
78+
6479 /**
6580 * Imports the MapGeometry from its JSON representation. M and Z values are
6681 * not imported from JSON representation.
@@ -75,7 +90,7 @@ public static MapGeometry jsonToGeometry(JsonParser json) {
7590 * @throws IOException
7691 * @throws JsonParseException
7792 */
78- public static MapGeometry jsonToGeometry (String json ) throws JsonParseException , IOException {
93+ public static MapGeometry jsonToGeometry (String json ) {
7994 MapGeometry geom = OperatorImportFromJson .local ().execute (Geometry .Type .Unknown , json );
8095 return geom ;
8196 }
@@ -126,43 +141,60 @@ public static String geometryToGeoJson(Geometry geometry) {
126141 return exporter .execute (geometry );
127142 }
128143
129- /**
130- * Exports the specified geometry instance to its GeoJSON representation.
131- *
132- *See OperatorExportToGeoJson.
133- *
134- * @see GeometryEngine#geometryToGeoJson(SpatialReference spatialReference,
135- * Geometry geometry)
136- *
137- * @param wkid
138- * The spatial reference Well Known ID to be used for the GeoJSON representation.
139- * @param geometry
140- * The geometry to be exported to GeoJSON.
141- * @return The GeoJSON representation of the specified geometry.
142- */
143- public static String geometryToGeoJson ( int wkid , Geometry geometry ) {
144- return GeometryEngine . geometryToGeoJson (
145- wkid > 0 ? SpatialReference . create ( wkid ) : null , geometry ) ;
146- }
144+ /**
145+ * Imports the MapGeometry from its JSON representation. M and Z values are
146+ * not imported from JSON representation.
147+ *
148+ * See OperatorImportFromJson.
149+ *
150+ * @param json
151+ * The JSON representation of the geometry (with spatial
152+ * reference).
153+ * @return The MapGeometry instance containing the imported geometry and its
154+ * spatial reference.
155+ * @throws IOException
156+ * @throws JsonParseException
157+ */
158+ public static MapGeometry geoJsonToGeometry ( String json , int importFlags , Geometry . Type type ) {
159+ MapGeometry geom = OperatorImportFromGeoJson . local (). execute ( importFlags , type , json , null );
160+ return geom ;
161+ }
147162
148- /**
149- * Exports the specified geometry instance to it's JSON representation.
150- *
151- *See OperatorImportFromGeoJson.
152- *
153- * @param spatialReference
154- * The spatial reference of associated object.
155- * @param geometry
156- * The geometry.
157- * @return The GeoJSON representation of the specified geometry.
158- */
159- public static String geometryToGeoJson (SpatialReference spatialReference ,
160- Geometry geometry ) {
161- OperatorExportToGeoJson exporter = (OperatorExportToGeoJson ) factory
162- .getOperator (Operator .Type .ExportToGeoJson );
163+ /**
164+ * Exports the specified geometry instance to its GeoJSON representation.
165+ *
166+ * See OperatorExportToGeoJson.
167+ *
168+ * @see GeometryEngine#geometryToGeoJson(SpatialReference spatialReference,
169+ * Geometry geometry)
170+ *
171+ * @param wkid
172+ * The spatial reference Well Known ID to be used for the GeoJSON
173+ * representation.
174+ * @param geometry
175+ * The geometry to be exported to GeoJSON.
176+ * @return The GeoJSON representation of the specified geometry.
177+ */
178+ public static String geometryToGeoJson (int wkid , Geometry geometry ) {
179+ return GeometryEngine .geometryToGeoJson (wkid > 0 ? SpatialReference .create (wkid ) : null , geometry );
180+ }
163181
164- return exporter .execute (spatialReference , geometry );
165- }
182+ /**
183+ * Exports the specified geometry instance to it's JSON representation.
184+ *
185+ * See OperatorImportFromGeoJson.
186+ *
187+ * @param spatialReference
188+ * The spatial reference of associated object.
189+ * @param geometry
190+ * The geometry.
191+ * @return The GeoJSON representation of the specified geometry.
192+ */
193+ public static String geometryToGeoJson (SpatialReference spatialReference , Geometry geometry ) {
194+ OperatorExportToGeoJson exporter = (OperatorExportToGeoJson ) factory .getOperator (Operator .Type .ExportToGeoJson );
195+
196+ return exporter .execute (spatialReference , geometry );
197+ }
166198
167199 /**
168200 * Imports geometry from the ESRI shape file format.
@@ -230,26 +262,6 @@ public static Geometry geometryFromWkt(String wkt, int importFlags,
230262 return op .execute (importFlags , geometryType , wkt , null );
231263 }
232264
233- /**
234- * Imports a geometry from a geoJson string.
235- *
236- * See OperatorImportFromGeoJson.
237- *
238- * @param geoJson The string containing the geometry in geoJson format.
239- * @param importFlags Use the {@link GeoJsonImportFlags} interface.
240- * @param geometryType The required type of the Geometry to be imported. Use Geometry.Type.Unknown if the geometry type needs to be determined from the geoJson context.
241- * @return The geometry.
242- * @throws GeometryException when the geometryType is not Geometry.Type.Unknown and the geoJson contains a geometry that cannot be converted to the given geometryType.
243- * @throws IllegalArgument exception if an error is found while parsing the geoJson string.
244- */
245- @ Deprecated
246- public static MapGeometry geometryFromGeoJson (String geoJson ,
247- int importFlags , Geometry .Type geometryType ) throws JSONException {
248- OperatorImportFromGeoJson op = (OperatorImportFromGeoJson ) factory
249- .getOperator (Operator .Type .ImportFromGeoJson );
250- return op .execute (importFlags , geometryType , geoJson , null );
251- }
252-
253265 /**
254266 * Exports a geometry to a string in WKT format.
255267 *
0 commit comments