【问题标题】:Unable to see shapefile on the device无法在设备上看到 shapefile
【发布时间】:2015-09-03 14:00:29
【问题描述】:

我正在尝试在我的 android 应用程序中为建筑物添加 london shapefile。但是,我无法显示它。它在地图上什么也没有显示。但是相同的 shapefile 正在在线正确显示。所以,shapefile 没有任何问题。

我从以下位置下载 shapefile https://docs.google.com/uc?id=0B0kRhiw4fD7uQzU3MzBMRzFfSFk&export=download

我的代码: 布局.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();
    }

【问题讨论】:

    标签: android gis arcgis


    【解决方案1】:

    您需要进行两项更改:

    1. MapView 不会即时重新投影ShapefileFeatureTable。 shapefile 必须与地图位于相同的空间参考中。首先添加 WGS 1984 空间参考中的地图服务,它将MapView 的空间参考设置为 WGS 1984。但 shapefile 位于英国国家网格中。您必须 1) 使用 ArcMap 将 shapefile 投影到 WGS 1984 并将新 shapefile 推送到您的设备或 2) 不将地图服务图层添加到地图。 MapView 也不会即时重新投影平铺服务,因此如果您想在 Android 中同时显示这两个图层,则必须提前投影 shapefile。

    2. 你给你的SimpleRenderer 一个SimpleMarkerSymbolSimpleMarkerSymbol 仅用于积分。对于多边形,例如您共享的 shapefile,您必须改用 SimpleFillSymbol。所以做这样的事情:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多