java利用arcgis service rest服务进行坐标投影转换

转换参数说明

arcgis service rest的project服务参数

    Input Spatial Reference(inSR):输入坐标系

    Output Spatial Reference(outSR):输出坐标系

    Geometries(geometries):输入转换的坐标JSON,可以是点、线、面

    Datum Transformation(transformation):坐标转换参数

    Transform Forward(transformForward):是否参数转换?

    Format(f):输出类型JSON或者HTML

定义Geometries类

首先定义一个RestGeometries类,方便生成Geometries的json字符串

import java.util.ArrayList;
import java.util.List;

public class RestGeometries {

	private String geometryType;

	private List<Rings> geometries = new ArrayList<Rings>();

	public String getGeometryType() {
		return geometryType;
	}

	public void setGeometryType(String geometryType) {
		this.geometryType = geometryType;
	}

	public List<Rings> getGeometries() {
		return geometries;
	}

	public void setGeometries(List<Rings> geometries) {
		this.geometries = geometries;
	}
}

其中geometryType 可以是

<esriGeometryPoint | esriGeometryMultipoint | esriGeometryPolyline | esriGeometryPolygon>

另外上面涉及一个类Rings用于存储坐标点

import java.util.ArrayList;
import java.util.List;

public class Rings {
	
	private List<List<double[]>> rings = new ArrayList<List<double[]>>();
	
	public List<List<double[]>> getRings() {
		return rings;
	}

	public void setRings(List<List<double[]>> rings) {
		this.rings = rings;
	}
}

测试一下,生成一个Geometries

public String makeGeometries() {
		RestGeometries g = new RestGeometries();
		g.setGeometryType("esriGeometryPolygon");
		double[] point11 = new double[] { -117,34 };
		double[] point12 = new double[] { -116,34 };
		double[] point13 = new double[] { -117,33 };
		double[] point14 = new double[] { -117,34 };
		double[] point15 = new double[] { -115,44 };

		List<double[]> ring1 = new ArrayList<double[]>();
		ring1.add(point11);
		ring1.add(point12);
		ring1.add(point13);
		ring1.add(point14);
		ring1.add(point15);
		
		double[] point21 = new double[] { 32,17 };
		double[] point22 = new double[] { 31,17 };
		double[] point23 = new double[] { 30,17 };
		double[] point24 = new double[] { 30,16 };
		double[] point25 = new double[] { 32,17 };
		
		List<double[]> ring2 = new ArrayList<double[]>();
		ring2.add(point21);
		ring2.add(point22);
		ring2.add(point23);
		ring2.add(point24);
		ring2.add(point25);

		Rings rings1 = new Rings();
		rings1.getRings().add(ring1);
		Rings rings2 = new Rings();
		rings2.getRings().add(ring2);
		g.getGeometries().add(rings1);
		g.getGeometries().add(rings2);

		return JSON.toJSONString(g);
}

输出:

{"geometries": 
    [
        {"rings": [[[-117,34],[-116,34],[-117,33],[-117,34],[-115,44]]]},
        {"rings": [[[32,17],[31,17],[30,17],[30,16],[32,17]]]}
    ],
    "geometryType": "esriGeometryPolygon"
}

利用httpclient访问Rest进行坐标转换

public String project() {
		//StringBuffer sb = new StringBuffer();
		HttpClient client = new DefaultHttpClient();
		HttpPost request = new HttpPost("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project");
		// 设置HTTP POST请求参数必须用NameValuePair
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("f", "json"));// format设置成json
		params.add(new BasicNameValuePair("inSR", "4326"));
		params.add(new BasicNameValuePair("outSR", "3857"));
		params.add(new BasicNameValuePair("geometries", makeGeometries()));
        //params.add(new BasicNameValuePair("transformation", sb.toString()));
		//params.add(new BasicNameValuePair("transformForward", "true"));
		try {
			HttpEntity entity = new UrlEncodedFormEntity(params);
			request.setEntity(entity);
			HttpResponse response = client.execute(request);
			if (response.getStatusLine().getStatusCode() == 200) {// 如果状态码为200,就是正常返回
				return EntityUtils.toString(response.getEntity());
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
		}
		return null;
	}

输出

{"geometries":[
   {"rings":[[[-12913060.932019727,4028802.0261344141],
              [-13024380.422813002,3895303.9633939015],
              [-13024380.422813002,4028802.0261344141],
              [-12913060.932019727,4028802.0261344141]]]},
   {"rings":[[[3562223.7053847606,1920825.040377473],
              [3339584.7237982131,1804722.7662572993],
              [3339584.7237982131,1920825.040377473],
              [3450904.2145914868,1920825.040377473],
              [3562223.7053847606,1920825.040377473]]]}
     ]
}

关于Datum Transformation(transformation) 参数

通常我们说的七参数转换,可以通过给这个参数赋值来进行坐标转换,这个参数是个JSON字符串,可以通过以下方法赋值进行坐标转换:

String dataNum = "{'wkt':GEOGTRAN[\"MGI_To_ETRS_1989_4\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],GEOGCS[\"GCS_ETRS_1989\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],METHOD[\"Coordinate_Frame\"],PARAMETER[\"X_Axis_Translation\",601.705],PARAMETER[\"Y_Axis_Translation\",84.263],PARAMETER[\"Z_Axis_Translation\",485.227],PARAMETER[\"X_Axis_Rotation\",-4.7354],PARAMETER[\"Y_Axis_Rotation\",-1.3145],PARAMETER[\"Z_Axis_Rotation\",-5.393],PARAMETER[\"Scale_Difference\",-2.3887]]}"
params.add(new BasicNameValuePair("transformation", dataNum));
params.add(new BasicNameValuePair("transformForward", "true"));

arcgis中可以通过toolbox提供的工具创建一个自定义的transformation

121132_Xvxb_351612.png

 

转载于:https://my.oschina.net/u/351612/blog/798712

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值