无法在设备上看到 shapefile

Unable to see shapefile on the device

我正尝试在我的 android 应用程序中添加建筑物的伦敦 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();
    }

您需要进行两项更改:

  1. MapView will not re-project ShapefileFeatureTable 进行中。 shapefile 必须与地图具有相同的空间参考。您首先添加一个位于 WGS 1984 空间参考中的地图服务,它将 MapView 的空间参考设置为 WGS 1984。但是 shapefile 位于英国国家网格中。您必须 1) 使用 ArcMap 将 shapefile 投影*到 WGS 1984 并将新的 shapefile 推送到您的设备或 2) 不将地图服务图层添加到地图。 MapView 也不会即时重新投影切片服务,因此如果您想在 Android.[=22= 中同时显示这两个图层,则必须提前投影 shapefile ]

  2. 你给的是 SimpleRenderer a SimpleMarkerSymbol. SimpleMarkerSymbol is only for points. For polygons, like the shapefile you shared, you must use a SimpleFillSymbol。所以做这样的事情:

    SimpleFillSymbol symbol = new SimpleFillSymbol(Color.CYAN, SimpleFillSymbol.STYLE.SOLID);
    symbol.setOutline(new SimpleLineSymbol(Color.LTGRAY, 1));
    

* 取消投影,实际上,因为您要从投影坐标系转到地理坐标系,但是使用 Project 工具来完成它。