如何在arcgis中添加用户纬度和经度值。

时间:2014-09-25 06:22:28

标签: java arcgis

我在项目中使用ArcGIS Runtime SDK for Java。我需要为GPS跟踪添加纬度/经度值。我无法找到解决方案来执行此操作。有一些示例代码可以执行此操作,但我认为他们使用CSV文件作为值。

我无法找到添加CSV文件路径或添加CSV文件的方法。

示例代码:

private static final String FSP = System.getProperty("file.separator");

private String getPathSampleData() {
    String dataPath = null;
    String javaPath = ArcGISRuntime.getInstallDirectory();
    if (javaPath != null) {
        if (!(javaPath.endsWith("/") || javaPath.endsWith("\\"))) {
            javaPath += FSP;
        }
        dataPath = javaPath + "sdk" + FSP + "samples" + FSP + "data" + FSP;
    }
    File dataFile = new File(dataPath);
    if (!dataFile.exists()) { 
        dataPath = ".." + FSP + "data" + FSP;
    }
    return dataPath;
}

任何人都可以帮我解决我的问题吗?

1 个答案:

答案 0 :(得分:1)

您提到了GPS和CSV,我将解释如何在ArcGIS Runtime中使用它们。

GPS

使用GPSLayer类在地图上显示位置信息流。使用GPSLayer有几个选项:

  1. 使用SerialPortGPSWatcher连接到串行端口(或虚拟串行端口)GPS(sample)。
  2. 使用FileGPSWatcher来使用GPS点的NMEA文件(sample 1sample 2)。
  3. 实施IGPSWatcher界面以执行除真实GPS或NMEA文件之外的其他操作,例如CSV文件。
  4. CSV

    如果您真正想要的是在地图上显示CSV,我可以考虑两个选项:

    1. 自行解析CSV并将结果放入GraphicsLayersample)。 (在Java中有1,001种解析CSV的方法;如果我正在编写该代码,BufferedReaderStringTokenizer将成为我的朋友。)
    2. 使用CSVLayer课程。没有任何样本,并且它没有很好地记录,因为它似乎是为内部使用而编写的,用于显示存储在Web地图中的CSV图层。但您可以将其与CSV文件一起使用,如下所示:

      //map is of type JMap
      map.addMapEventListener(new MapEventListenerAdapter() {
          @Override
          public void mapReady(MapEvent event) {
              String layerDef = "{   \"geometryType\": \"esriGeometryPoint\",   \"type\": \"Feature Layer\",   \"typeIdField\": \"\",   \"drawingInfo\": {     \"renderer\": {       \"type\": \"simple\",       \"symbol\": {         \"type\": \"esriSMS\",         \"style\": \"esriSMSCircle\",         \"color\": [200, 40, 0, 255],         \"size\": 15,         \"angle\": 0,         \"xoffset\": 0,         \"yoffset\": 0       }     },     \"fixedSymbols\": true   },   \"fields\": [     {       \"name\": \"X\",       \"alias\": \"X\",       \"type\": \"esriFieldTypeDouble\",       \"editable\": true,       \"nullable\": true,       \"domain\": null     },     {       \"name\": \"Y\",       \"alias\": \"Y\",       \"type\": \"esriFieldTypeDouble\",       \"editable\": true,       \"nullable\": true,       \"domain\": null     }   ],   \"name\": \"My CSV Layer\" }";
              CSVLayer.CSVConfig csvConfig = new CSVLayer.CSVConfig();
              csvConfig.url = new File("/path/to/csv-file.csv").toURI().toString();
              csvConfig.columnDelimiter = ",";
              csvConfig.longitudeField = "X";
              csvConfig.latitudeField = "Y";
              try {
                  final CSVLayer csvLayer = new CSVLayer(layerDef, csvConfig);
                  map.getLayers().add(csvLayer);
              } catch (Exception ex) {
                  //Handle the exception
              }
          }
      });
      
    3. 不幸的是,您确实需要JSON字符串才能使用CSVLayer。我使JSON字符串尽可能简单。如果经度和纬度的字段名称不是XY,则需要对其进行调整。您可以看到layerDefinition schema documentation和更详尽的示例(descriptionJSON)。

      选项2所需的JSON字符串使得选项1在我看来是更好的选择。解析CSV很容易;管理那个JSON字符串更难。