EsriJSON与GeoJSON转换工具类。简单的点线面应该没问题,复杂的可能有问题,没具体测试。大家可以在这个基础上修改。后面用起来慢慢修正吧。
package piesat.geo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.util.*;
public class EsriGeoJsonUtil {
public static String esri2geo(String ersiJson){
Map geoMap = new HashMap();
try {
List geoFs = new ArrayList();
geoMap.put("type", "FeatureCollection");
Map esriMap = (Map) JSON.parse(ersiJson);
Object esriFs = esriMap.get("features");
if(esriFs instanceof List){
esriFs = (List<Map<String, Object>>) esriFs;
for(int i=0; i< ((List) esriFs).size(); i++){
Map esriF = (Map) ((List) esriFs).get(i);
Map geoF = new HashMap();
geoF.put("type", "Feature");
geoF.put("properties", esriF.get("attributes"));
Map<String, Object> geometry = (Map<String, Object>) esriF.get("geometry");
if(null != geometry.get("x")){
geoF.put("geometry", geoPoint(geometry));
}else if(null != geometry.get("points")){
geoF.put("geometry", geoPoints(geometry));
}else if(null != geometry.get("paths")){
geoF.put("geometry", geoLine(geometry));
}else if(null != geometry.get("rings")){
geoF.put("geometry", geoPoly(geometry));
}
geoFs.add(geoF);
}
geoMap.put("features", geoFs);
}
}catch (Exception e){
e.printStackTrace();
}
return new JSONObject(geoMap).toString();
}
public static String geo2ersi(String geoJson, String idAttribute){
Map esriMap = new HashMap();
try {
Map geoMap = (Map) JSON.parse(geoJson);
esriMap = getEsriGeo(geoMap, idAttribute);
Map spatialReference = new HashMap();
spatialRef
EsriJSON与GeoJSON转换工具类
最新推荐文章于 2026-05-05 09:55:27 发布
本文介绍了一个用于转换EsriJSON与GeoJSON格式的工具类,包括点、线、面等几何对象的相互转换方法。该工具类使用Java实现,能够处理简单的地理数据,并提供了一系列实用的静态方法。


1199

被折叠的 条评论
为什么被折叠?



