geoc_gcj02towgs84_point.sql 691 B

1234567891011121314151617181920212223242526
  1. CREATE OR REPLACE FUNCTION "public"."geoc_gcj02towgs84_point"("geom" "public"."geometry")
  2. RETURNS "public"."geometry" AS $BODY$
  3. DECLARE
  4. tempPoint numeric[];
  5. wgsLon numeric;
  6. wgsLat numeric;
  7. lon numeric;
  8. lat numeric;
  9. BEGIN
  10. if st_geometrytype(geom) != 'ST_Point' then
  11. return geom;
  12. end if;
  13. lon := st_x(geom);
  14. lat := st_y(geom);
  15. if geoc_is_in_china_bbox(lon, lat) = false THEN
  16. return geom;
  17. end if;
  18. tempPoint := geoc_wgs84togcj02(ARRAY[lon, lat]);
  19. wgsLon := lon*2 - tempPoint[1];
  20. wgsLat := lat*2 - tempPoint[2];
  21. return st_makepoint(wgsLon,wgsLat);
  22. END;
  23. $BODY$
  24. LANGUAGE plpgsql VOLATILE
  25. COST 100