我有一個表geofences
,它存儲了多邊形的geometry
。Postgis幾何邊界上的兩個最近點
我也有一個點A
這是幾何內。我需要做的是找到位於多邊形幾何體表面上的點A
的兩個最近點。
功能在PostGIS的:
CREATE OR REPLACE FUNCTION accuracyCheck(Polygon geometry
,decimal lat
,decimal lon)
RETURNS VARCHAR AS
$BODY$
DECLARE height DECIMAL;
DECLARE accuracy VARCHAR(250);
BEGIN
CREATE TEMPORARY TABLE closePointStorage AS
SELECT ST_AsText(ST_ClosestPoint(geometry
,ST_GeomFromText('POINT(lat lon)',0)
)
) AS closestPoint
FROM (
SELECT ST_GeomFromText(geometry) as geometry
FROM gfe_geofences
WHERE is_active=true
) As tempName;
CREATE TEMPORARY TABLE areaStorage ON COMMIT DROP AS
SELECT ST_Area(ST_GeomFromText('Polygon((23.0808622876029 96.1304006624291
,28.0808622876029 99.1304006624291
,100 200
,23.0808622876029 96.1304006624291
))'
,0)
) AS area;
CREATE TEMPORARY TABLE distanceStorage ON COMMIT DROP AS
SELECT ST_Distance(
ST_GeomFromText('POINT(23.0808622876029 96.1304006624291)',-1)
,ST_GeomFromText('POINT(28.0808622876029 99.1304006624291)',-1)
) AS distance;
height = (SELECT area FROM areaStorage)
/(0.5*(SELECT distance FROM distanceStorage));
IF height < (SELECT radius_meters
FROM gfe_geofences Where is_active=true) THEN
accuracy = "FullConfirm";
RETURN accuracy;
ELSE
accuracy = "PartiallyConfirm";
RETURN accuracy;
END IF;
END;
$BODY$ LANGUAGE plpgsql;
我只是想找到多邊形形狀的邊界兩分。就像我已經找到一個從查詢:
CREATE TEMPORARY TABLE closePointStorage AS
SELECT ST_AsText(ST_ClosestPoint(geometry
,ST_GeomFromText('POINT(lat lon)',0)
)
) AS closestPoint
FROM (
SELECT ST_GeomFromText(geometry) as geometry
FROM gfe_geofences
WHERE is_active=true
)
AS tempName;
其他然後這一點我必須找到一個更隨距離大於點發現以上,但隨後小點的休息。
double lat1 = Math.toRadians(26.5534d); \t \t double lon1 = Math.toRadians(75.4925d); \t \t double lat2 = Math.toRadians(28.3650d); \t \t double lon2 = Math.toRadians(77.1232d); \t \t double dellat =(lat2 - lat1); \t \t double dellon =(lon2 - lon1); \t \t double R = 6371; \t \t雙A = Math.sin((dellat)/ 2)* Math.sin((dellat)/ 2) \t \t \t \t + Math.cos(LAT1)* Math.cos(LAT2)* Math.sin ((dellon)/ 2) \t \t \t \t * Math.sin((dellon)/ 2); (數學公式2(Math.sqrt(a),Math.sqrt(1-a))); \t \t double d = R * c; System.out.println(「km的距離值=」+ d); –
計算了從A點到幾何點的每個點的循環距離,並找出距離所有點的最小或最小距離。 –
如果您只關心幾何體中的點,而不關心點之間的線段,則可以將多邊形的邊界轉換爲MULTIPOINT,找到最近的點,將其移除,然後找到第二個最近的點。 –