我正在尝试在我的Android应用中为建筑物添加london shapefile。但是,我无法显示它。它在地图上没有显示任何内容。但是相同的shapefile可以在线正确显示。所以,shapefile没有任何问题。
我从中下载了shapefile https://docs.google.com/uc?id=0B0kRhiw4fD7uQzU3MzBMRzFfSFk&export=download
我的代码: layout.xml
<!-- MapView layout and initial basemap and extent. -->
<com.esri.android.map.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapoptions.ZoomLevel="5"
mapoptions.center="18.0000, 79.5800" >
</com.esri.android.map.MapView>
MapActivity.java
mMapView = (MapView) findViewById(R.id.map);
mMapView.enableWrapAround(true);
String mShapefilePath = "/london_buildings/TQTL_LON.shp";
String mSdcard = Environment.getExternalStorageDirectory().getPath();
mMapView = (MapView) findViewById(R.id.map);
ArcGISTiledMapServiceLayer mTiledlayer = new ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/arcgis/rest/services/ESRI_Imagery_World_2D/MapServer");
mMapView.addLayer(mTiledlayer);
try {
shpFileFeatTable = new ShapefileFeatureTable(mSdcard + mShapefilePath);
mFlayer = new FeatureLayer(shpFileFeatTable);
mFlayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(Color.CYAN, 2, STYLE.SQUARE)));
mMapView.addLayer(mFlayer);
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "File not found in SDCard, nothing to load", Toast.LENGTH_LONG)
.show();
} catch (RuntimeException e) {
Log.d("**ShapefileTest**", "File not found in SDCard, nothing to load");
Toast.makeText(getApplicationContext(), "File not found in SDCard, nothing to load", Toast.LENGTH_LONG)
.show();
}
答案 0 :(得分:0)
您需要进行两项更改:
MapView
不会动态重新投放ShapefileFeatureTable
。 shapefile必须与地图位于相同的空间参考中。首先添加WGS 1984空间参考中的地图服务,该地图服务将MapView
的空间参考设置为WGS 1984.但是shapefile位于英国国家网格中。您必须1)使用ArcMap将shapefile投影到WGS 1984并将新shapefile推送到您的设备或2)不将地图服务图层添加到地图。 MapView
无法动态重新投影平铺服务,因此如果您想在Android中同时显示这两个图层,则必须提前投影shapefile。
您已经SimpleRenderer
了SimpleMarkerSymbol
。 SimpleMarkerSymbol
仅适用于积分。对于多边形,例如您共享的shapefile,您必须使用SimpleFillSymbol
代替。所以做这样的事情:
SimpleFillSymbol symbol = new SimpleFillSymbol(Color.CYAN, SimpleFillSymbol.STYLE.SOLID);
symbol.setOutline(new SimpleLineSymbol(Color.LTGRAY, 1));
*实际上,取消投影,因为您从投影坐标系转到地理坐标系,但使用Project工具进行投影。