如何在Java中仅生成海洋坐标并在可视化地图中显示它们
我正在制作一种跟踪应用程序,需要为不同的船只生成坐标,并在地图上显示它们的位置 我研究过类似的问题,但都是关于陆地坐标的。另外,我也看到过很多不同的框架,比如GeoTools或Unfollowing,但是文档太大了,我找不到我想要的 我只需要在海洋上生成坐标,然后在地图上显示标签 在Python中,有一个库可以检查一个点是否在陆地上(因此您可以检查它是否在海洋上),然后使用Folium可以添加带有传统信息的标记如何在Java中仅生成海洋坐标并在可视化地图中显示它们,java,coordinates,geotools,Java,Coordinates,Geotools,我正在制作一种跟踪应用程序,需要为不同的船只生成坐标,并在地图上显示它们的位置 我研究过类似的问题,但都是关于陆地坐标的。另外,我也看到过很多不同的框架,比如GeoTools或Unfollowing,但是文档太大了,我找不到我想要的 我只需要在海洋上生成坐标,然后在地图上显示标签 在Python中,有一个库可以检查一个点是否在陆地上(因此您可以检查它是否在海洋上),然后使用Folium可以添加带有传统信息的标记 不知道Java是否有类似的方法。下载我的海洋网格坐标: 该文件可能在不久的将来被删
不知道Java是否有类似的方法。下载我的海洋网格坐标: 该文件可能在不久的将来被删除 如何使用它:
String fromFile = FileUtils.readFileToString( new File( "c:/users/you/downloads/coordinates.json" ), "UTF-8" );
JSONArray coordinates = new JSONArray( fromFile );
// pull random coordinates from the array:
int index = (int) (Math.random() * coordinates.length() );
JSONObject randomCoordinate = coordinates.getJSONObject( index );
double longitude = randomCoordinate.getDouble( "lo" );
double latitude = randomCoordinate.getDouble( "la" );
必需的pom.xml
依赖项:
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
org.json
json
20190722
公地io
公地io
2.6
仅下载我的海洋网格坐标:
该文件可能在不久的将来被删除
如何使用它:
String fromFile = FileUtils.readFileToString( new File( "c:/users/you/downloads/coordinates.json" ), "UTF-8" );
JSONArray coordinates = new JSONArray( fromFile );
// pull random coordinates from the array:
int index = (int) (Math.random() * coordinates.length() );
JSONObject randomCoordinate = coordinates.getJSONObject( index );
double longitude = randomCoordinate.getDouble( "lo" );
double latitude = randomCoordinate.getDouble( "la" );
必需的pom.xml
依赖项:
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
org.json
json
20190722
公地io
公地io
2.6
我会这样做:
public class PointInSea {
private static final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2();
private SimpleFeatureCollection features;
public static void main(String[] args) throws IOException {
URL url = new URL("https://datahub.io/core/geo-countries/r/countries.geojson");
Map<String, Object> params = new HashMap<>();
params.put(GeoJSONDataStoreFactory.URL_PARAM.key, url);
DataStore ds = DataStoreFinder.getDataStore(params);
PointInSea me = new PointInSea();
me.setFeatures(ds.getFeatureSource(ds.getTypeNames()[0]).getFeatures());
List<Point> ret = me.getPoints(10);
for (Point p : ret) {
System.out.println(p);
}
}
private void setFeatures(SimpleFeatureCollection features2) throws IOException {
features = new SpatialIndexFeatureCollection(features2);
}
private List<Point> getPoints(int i) {
List<Point> ret = new ArrayList<>(i);
for (int count = 0; count < i; count++) {
Point p = createRandomPoint();
Contains filter = FF.contains(FF.property(features.getSchema().getGeometryDescriptor().getLocalName()),
FF.literal(p));
while (features.subCollection(filter).size() != 0) {
p = createRandomPoint();
filter = FF.contains(FF.property(features.getSchema().getGeometryDescriptor().getLocalName()), FF.literal(p));
}
ret.add(p);
}
return ret;
}
public static Point createRandomPoint() {
double latitude = (Math.random() * 180.0) - 90.0;
double longitude = (Math.random() * 360.0) - 180.0;
GeometryFactory geometryFactory = new GeometryFactory();
Point point;
if (CRS.getAxisOrder(DefaultGeographicCRS.WGS84) == CRS.AxisOrder.EAST_NORTH) {
/* Longitude (= x coord) first ! */
point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
} else {
point = geometryFactory.createPoint(new Coordinate(latitude, longitude));
}
return point;
}
}
公共类PointInSea{
私有静态最终FilterFactory2 FF=CommonFactoryFinder.getFilterFactory2();
私有SimpleFeatureCollection功能;
公共静态void main(字符串[]args)引发IOException{
URL=新URL(“https://datahub.io/core/geo-countries/r/countries.geojson");
Map params=新的HashMap();
参数put(GeoJSONDataStoreFactory.URL_PARAM.key,URL);
DataStore ds=DataStoreFinder.getDataStore(params);
PointInSea me=新的PointInSea();
me.setFeatures(ds.getFeatureSource(ds.getTypeNames()[0]).getFeatures());
List ret=me.getPoints(10);
对于(p点:ret){
系统输出println(p);
}
}
私有void集合功能(SimpleFeatureCollection功能2)引发IOException{
特征=新的SpatialIndexFeatureCollection(特征2);
}
私有列表获取点(int i){
List ret=新阵列列表(i);
对于(int count=0;count
我会这样做:
public class PointInSea {
private static final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2();
private SimpleFeatureCollection features;
public static void main(String[] args) throws IOException {
URL url = new URL("https://datahub.io/core/geo-countries/r/countries.geojson");
Map<String, Object> params = new HashMap<>();
params.put(GeoJSONDataStoreFactory.URL_PARAM.key, url);
DataStore ds = DataStoreFinder.getDataStore(params);
PointInSea me = new PointInSea();
me.setFeatures(ds.getFeatureSource(ds.getTypeNames()[0]).getFeatures());
List<Point> ret = me.getPoints(10);
for (Point p : ret) {
System.out.println(p);
}
}
private void setFeatures(SimpleFeatureCollection features2) throws IOException {
features = new SpatialIndexFeatureCollection(features2);
}
private List<Point> getPoints(int i) {
List<Point> ret = new ArrayList<>(i);
for (int count = 0; count < i; count++) {
Point p = createRandomPoint();
Contains filter = FF.contains(FF.property(features.getSchema().getGeometryDescriptor().getLocalName()),
FF.literal(p));
while (features.subCollection(filter).size() != 0) {
p = createRandomPoint();
filter = FF.contains(FF.property(features.getSchema().getGeometryDescriptor().getLocalName()), FF.literal(p));
}
ret.add(p);
}
return ret;
}
public static Point createRandomPoint() {
double latitude = (Math.random() * 180.0) - 90.0;
double longitude = (Math.random() * 360.0) - 180.0;
GeometryFactory geometryFactory = new GeometryFactory();
Point point;
if (CRS.getAxisOrder(DefaultGeographicCRS.WGS84) == CRS.AxisOrder.EAST_NORTH) {
/* Longitude (= x coord) first ! */
point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
} else {
point = geometryFactory.createPoint(new Coordinate(latitude, longitude));
}
return point;
}
}
公共类PointInSea{
私有静态最终FilterFactory2 FF=CommonFactoryFinder.getFilterFactory2();
私有SimpleFeatureCollection功能;
公共静态void main(字符串[]args)引发IOException{
URL=新URL(“https://datahub.io/core/geo-countries/r/countries.geojson");
Map params=新的HashMap();
参数put(GeoJSONDataStoreFactory.URL_PARAM.key,URL);
DataStore ds=DataStoreFinder.getDataStore(params);
PointInSea me=新的PointInSea();
me.setFeatures(ds.getFeatureSource(ds.getTypeNames()[0]).getFeatures());
List ret=me.getPoints(10);
对于(p点:ret){
系统输出println(p);
}
}
私有void集合功能(SimpleFeatureCollection功能2)引发IOException{
特征=新的SpatialIndexFeatureCollection(特征2);
}
私有列表获取点(int i){
List ret=新阵列列表(i);
对于(int count=0;count
你确定你真的需要知道一个纵向/纬度点是否在海洋中吗?你想追踪飞船,是不是飞船的指挥官