【问题标题】:ArcGIS create buffer using GeometryServer in androidArcGIS 在 android 中使用 GeometryServer 创建缓冲区
【发布时间】:2013-11-06 09:38:48
【问题描述】:

我正在尝试使用此 ArcGIS 服务在 android 周围创建一个缓冲区:

http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

我想使用这个以编程方式创建一个缓冲区:

http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/buffer

因为是学校作业所以必须是这个服务,并且API必须是ArcGIS SDK 10.1.1

不幸的是,没有太多关于此的文档。我所知道的是,在某个时刻我应该获得一个 Polygon 对象,我将把它添加到地图中。

我需要知道的是(有重点)如何调用服务,传递所需的参数并获取多边形。

谢谢

【问题讨论】:

  • 次要:没有适用于 Android 的 ArcGIS SDK 10.1。现在是 10.1.1。

标签: android buffer point arcgis arcgis-server


【解决方案1】:

如果我是你,我会跳过 GeometryServer 并使用 GeometryEngine.buffer(Geometry, SpatialReference, double, Unit)。您不需要以这种方式调用服务。 这是正确的做法。

但是,如果您的学校作业需要调用服务,请转到 the service 并单击 API 参考链接以调出 the documentation for GeometryServer。您必须使用 f=json 并使用 JSON。 GeometryEngine 有 geometryToJson 和 jsonToGeometry 方法可以帮助您,但如果您愿意,也可以使用 a JSON library。如果您不知道如何在 Android/Java 代码中打开 URL 连接,请使用 Google。

【讨论】:

    【解决方案2】:

    我正在使用 MapBox,我必须在地图上的 多边形 顶部创建一个缓冲区域。我没有使用 ArcGis,而是使用了 vividsolutions 的库
    Git 回购链接:https://github.com/RanaRanvijaySingh/MapBoxDemo

    build.gradle 文件中的添加

    dependencies {
       ...
       compile 'com.vividsolutions:jts:1.13'
    }
    

    MainActivity 中,我采用了具有以下几点的多边形:

    final List<LatLng> latLngPolygon = new ArrayList<>();
        {
            latLngPolygon.add(new LatLng(28.6139, 77.2090));//delhi
            latLngPolygon.add(new LatLng(22.2587, 71.1924));//gujarat
            latLngPolygon.add(new LatLng(18.5204, 73.8567));//pune
            latLngPolygon.add(new LatLng(12.9716, 77.5946));//banglore
            latLngPolygon.add(new LatLng(25.5941, 85.1376));//patna
            //this is needed to completed a covered area, without this it would not work
            latLngPolygon.add(new LatLng(28.6139, 77.2090));//delhi
        }
    

    以下是在地图上创建多边形和缓冲多边形的功能

    /**
     * Function is called on click of Buffer Example button
     *
     * @param view View
     */
    public void onClickBufferExample(View view) {
        //Initialize geometry factory object to get Geometry object.
        geometryFactory = new GeometryFactory();
        //Create geometry object using your own lat lang points
        //TODO : latLngPolygon - Used in this example is to show a bigger picture. Replace it
        //TODO : with your requirement.
        Geometry geometryOriginal = getGeometryForPolygon(latLngPolygon);
        //Draw polygon on map
        createPolygon(geometryOriginal);
        /**
         * Create geometry object with given buffer distance
         * Now buffer distance will vary on your requirement
         * Range could be anything
         * Hit and try
         */
        Geometry geometryBuffered = geometryOriginal.buffer(1);
        //Draw buffer polygon
        createPolygon(geometryBuffered);
    }
    
    /**
     * Function to get Geometry object (Class from vividsolutions)
     * from given list of latlng
     *
     * @param bounds List
     * @return Geometry (Class from vividsolutions)
     */
    public Geometry getGeometryForPolygon(List<LatLng> bounds) {
        List<Coordinate> coordinates = getCoordinatesList(bounds);
        if (!coordinates.isEmpty()) {
            return geometryFactory.createPolygon(getLinearRing(coordinates), null);
        }
        return null;
    }
    
    /**
     * Function to create a list of coordinates from a list of lat lng
     *
     * @param listLatLng list<LatLng>
     * @return List<Coordinate> (Class from vividsolutions)
     */
    private List<Coordinate> getCoordinatesList(List<LatLng> listLatLng) {
        List<Coordinate> coordinates = new ArrayList<>();
        for (int i = 0; i < listLatLng.size(); i++) {
            coordinates.add(new Coordinate(
                    listLatLng.get(i).getLatitude(), listLatLng.get(i).getLongitude()));
        }
        return coordinates;
    }
    
    /**
     * Function to create a polygon on the map
     *
     * @param geometry Geometry Class from vividsolutions
     */
    private void createPolygon(Geometry geometry) {
        LatLng[] points = getPoints(geometry.getCoordinates());
        mapboxMap.addPolyline(new PolylineOptions()
                .add(points)
                .width(4)
                .color(Color.parseColor("#FF0000")));
    }
    
    /**
     * Function to convert array of Coordinates (Class from vividsolutions)
     * to Android LatLng array
     *
     * @param coordinates Coordinates (Class from vividsolutions)
     * @return LatLng[]
     */
    @NonNull
    private LatLng[] getPoints(Coordinate[] coordinates) {
        List<LatLng> listPoints = new ArrayList<>();
        for (Coordinate coordinate : coordinates) {
            listPoints.add(new LatLng(coordinate.x, coordinate.y));
        }
        return listPoints.toArray(new LatLng[listPoints.size()]);
    }
    
    /**
     * Function to create LinearRing (Class from vividsolutions) from a list of
     * Coordinate (Class from vividsolutions)
     *
     * @param coordinates List
     * @return LinearRing
     */
    @NonNull
    private LinearRing getLinearRing(List<Coordinate> coordinates) {
        return new LinearRing(getPoints(coordinates), geometryFactory);
    }
    
    /**
     * Function to get points of CoordinateArraySequence (Class from vividsolutions)
     *
     * @param coordinates List (Class from vividsolutions)
     * @return CoordinateArraySequence (Class from vividsolutions)
     */
    @NonNull
    private CoordinateArraySequence getPoints(List<Coordinate> coordinates) {
        return new CoordinateArraySequence(getCoordinates(coordinates));
    }
    
    /**
     * Function to get coordinates array from a list of coordinates
     *
     * @param coordinates List<Coordinate> (Class from vividsolutions)
     * @return Coordinate [] (Class from vividsolutions)
     */
    @NonNull
    private Coordinate[] getCoordinates(List<Coordinate> coordinates) {
        return coordinates.toArray(new Coordinate[coordinates.size()]);
    }
    

    完成。
    按照您想要的方式进行重构,但就是这样。

    【讨论】:

      猜你喜欢
      • 2014-08-30
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 2015-05-15
      • 2015-08-25
      相关资源
      最近更新 更多