Skip to content

Add GeoJSON export ... #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 27, 2013
54 changes: 50 additions & 4 deletions src/com/esri/core/geometry/GeometryEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class GeometryEngine {

private static OperatorFactoryLocal factory = OperatorFactoryLocal
.getInstance();




/**
* Imports the MapGeometry from its JSON representation. M and Z values are
* not imported from JSON representation.
Expand Down Expand Up @@ -88,6 +90,47 @@ public static String geometryToJson(SpatialReference spatialReference,
return exporter.execute(spatialReference, geometry);
}

public static String geometryToGeoJson(Geometry geometry) {
OperatorExportToGeoJson exporter = (OperatorExportToGeoJson) factory
.getOperator(Operator.Type.ExportToGeoJson);

return exporter.execute(geometry);
}

/**
* Exports the specified geometry instance to its GeoJSON representation.
*
* @see GeometryEngine#geometryToGeoJson(SpatialReference spatialReference,
* Geometry geometry)
*
* @param wkid
* The spatial reference Well Known ID to be used for the GeoJSON representation.
* @param geometry
* The geometry to be exported to GeoJSON.
* @return The GeoJSON representation of the specified geometry.
*/
public static String geometryToGeoJson(int wkid, Geometry geometry) {
return GeometryEngine.geometryToGeoJson(
wkid > 0 ? SpatialReference.create(wkid) : null, geometry);
}

/**
* Exports the specified geometry instance to it's JSON representation.
*
* @param spatialReference
* The spatial reference of associated object.
* @param geometry
* The geometry.
* @return The GeoJSON representation of the specified geometry.
*/
public static String geometryToGeoJson(SpatialReference spatialReference,
Geometry geometry) {
OperatorExportToGeoJson exporter = (OperatorExportToGeoJson) factory
.getOperator(Operator.Type.ExportToGeoJson);

return exporter.execute(spatialReference, geometry);
}

/**
* Imports geometry from the ESRI shape file format.
*
Expand Down Expand Up @@ -557,7 +600,8 @@ public static Geometry[] cut(Geometry cuttee, Polyline cutter,

return cutsList.toArray(new Geometry[0]);
}



/**
* Calculates a buffer polygon for each geometry at each of the
* corresponding specified distances. It is assumed that all geometries have
Expand Down Expand Up @@ -600,7 +644,8 @@ public static Polygon[] buffer(Geometry[] geometries,
return buffers;
}
}



/**
* Calculates a buffer polygon of the geometry as specified by the
* distance input. The buffer is implemented in the xy-plane.
Expand Down Expand Up @@ -773,7 +818,8 @@ static boolean isSimple(Geometry geometry, SpatialReference spatialReference) {
boolean result = op.isSimpleAsFeature(geometry, spatialReference, null);
return result;
}



/**
* A geodesic distance is the shortest distance between any two points on the earth's surface when the earth's
* surface is approximated by a spheroid. The function returns the shortest distance between two points on the
Expand Down
2 changes: 1 addition & 1 deletion src/com/esri/core/geometry/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum Type {

Simplify, SimplifyOGC, Offset, Generalize,

ExportToWkb, ImportFromWkb, ExportToWkt, ImportFromWkt, ImportFromGeoJson, SymmetricDifference, ConvexHull, Boundary
ExportToWkb, ImportFromWkb, ExportToWkt, ImportFromWkt, ImportFromGeoJson, ExportToGeoJson, SymmetricDifference, ConvexHull, Boundary

}

Expand Down
43 changes: 43 additions & 0 deletions src/com/esri/core/geometry/OperatorExportToGeoJson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For additional information, contact:
Environmental Systems Research Institute, Inc.
Attn: Contracts Dept
380 New York Street
Redlands, California, USA 92373

email: contracts@esri.com
*/

package com.esri.core.geometry;

import com.esri.core.geometry.Operator.Type;

public abstract class OperatorExportToGeoJson extends Operator {
@Override
public Type getType() {
return Type.ExportToGeoJson;
}

abstract JsonCursor execute(SpatialReference spatialReference, GeometryCursor geometryCursor);

public abstract String execute(SpatialReference spatialReference, Geometry geometry);

public abstract String execute(Geometry geometry);

public static OperatorExportToGeoJson local() {
return (OperatorExportToGeoJson) OperatorFactoryLocal.getInstance()
.getOperator(Type.ExportToGeoJson);
}
}
Loading