如何用java实现“通过根据给定的经纬度生成区域”?

2024-12-24 11:41:47
推荐回答(2个)
回答1:

使用第三方jar包 jts包 例子如下面 \x0d\x0a\x0d\x0a//一个面所包含的经纬度(标准的经纬*3600000) \x0d\x0aString str = "POLYGON ((419164412 143703543, 419164481 143702737, 419164494 143702527,419164412 143703543))"; \x0d\x0aWKTReader wkt = new WKTReader(); \x0d\x0aGeometry geojudge1 = wkt.read(str); \x0d\x0aint xpoi = 419164481; \x0d\x0aint ypoi = 143702737; \x0d\x0aGeometry geojudge2 = wkt.read("POINT(" + xpoi + " " + ypoi + "))"); \x0d\x0a\x0d\x0aif(geojudge1.intersects(geojudge2)) { \x0d\x0aSystem.out.println("xpoi、ypoi 在这个面里"); \x0d\x0a} \x0d\x0a\x0d\x0aps:在构成一个面的时候,第一个点的经纬度一定要与最后一个点的经纬度相同。否则会报错误:java.lang.IllegalArgumentException: points must form a closed linestring

回答2:

使用第三方jar包 jts包 例子如下面

//一个面所包含的经纬度(标准的经纬*3600000)
String str = "POLYGON ((419164412 143703543, 419164481 143702737, 419164494 143702527,419164412 143703543))";
WKTReader wkt = new WKTReader();
Geometry geojudge1 = wkt.read(str);
int xpoi = 419164481;
int ypoi = 143702737;
Geometry geojudge2 = wkt.read("POINT(" + xpoi + " " + ypoi + "))");

if(geojudge1.intersects(geojudge2)) {
System.out.println("xpoi、ypoi 在这个面里");
}

ps:在构成一个面的时候,第一个点的经纬度一定要与最后一个点的经纬度相同。否则会报错误:java.lang.IllegalArgumentException: points must form a closed linestring