2013-10-27 30 views
2

我想在android系統使用本服務的ArcGIS 創建點周圍的緩衝區使用GeometryServer緩衝:的ArcGIS創建的Android

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

,我想以編程方式創建一個緩衝區使用這樣的:

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

這是一所學校的工作,所以它必須是該服務和API必須氬cGIS SDK 10.1.1

很不幸,關於這方面的文檔並不多。我所知道的是,在某個時刻,我應該獲得一個Polygon對象,我將它添加到地圖中。

我需要知道的是(重點)如何調用服務,傳遞所需參數並獲取多邊形。

謝謝

+0

小問題:Android上沒有ArcGIS SDK 10.1。它是10.1.1。 –

回答

0

如果我是你,我會跳過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。

1

我使用MapBox,我不得不創建在地圖上多邊形頂部的緩衝區域。我沒有使用過的ArcGIS相反,我使用圖書館從vividsolutions
混帳回購鏈接: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 
    } 

下面是創建多邊形和buffere的函數d多邊形

/** 
* 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()]); 
} 

DONE。
以您想要的方式繼續重構,但這就是它。