Draw a range of cameras using Postgis

I am working on some camera data. I have several points that consist of azimuth, angle, distance and, of course, field attributes of the field. In postgresql postgis, I want to draw such forms using functions.

how can i draw this pink range shape? first i have to draw a 360 degree circle and then draw from my shape ... i don't know how?

enter image description here

+6
source share
2 answers

I would create a circle around the point (x, y) with a radius of distance, and then use the information below to create a triangle with a greater height than the radius.

Then, using these two polygons, do ST_Intersection between the two geometries.

NOTE. This method only works if the angle is less than 180 degrees.

Note that if you lengthen the outer edges and meet them at an angle of 90 degrees from the middle of your arc, you have an angle and an adjacent side. Now you can SOH CAH TOA!

Extend and make right triangles

Get points B and C

Let the point A = (x, y)

To get the top point:

point B = (x + radius, y + (r * tan (angle)))

to get the bottom point:

point C = (x + radius, y - (r * tan (angle)))

Turn your triangle to you azimouth

Now that you have the triangle, you need to rotate it in your azimuth with pivot A. This means that you need point A at the origin when you rotate. Spinning is the hardest part. Its used in computer graphics all the time. (In fact, if you know OpenGL, you can get it to make a turn for you.)

NOTE. This method rotates counterclockwise at an angle (theta) around the origin. You may need to adjust your azimuth accordingly.

First step: translate your triangle so that A (your original x, y) is at 0,0. Regardless of what you added / subtracted at x and y, do the same for the other two points.

(You need to translate it, because you need to point A at the origin)

Second step: Then rotate points B and C using the rotation matrix. More details here , but I will give you the formula:

Rotation matrix

Your new point is (x', y') 

Do this for points B and C.

Third step: Transfer them back to their original location by adding or subtracting. If you subtracted x for the last time, add it this time.

Finally, use the points {A, B, C} to create a triangle.

And then do ST_Intersection (geom_circle, geom_triangle);

Since this requires a lot of calculations, it would be better to write a program that performs all these calculations and then fills the table.

+4
source

PostGIS supports curves, so one way to achieve this, which might require less math on your behalf, would be to do something like:

 SELECT ST_GeomFromText('COMPOUNDCURVE((0 0, 0 10), CIRCULARSTRING(0 10, 7.071 7.071, 10 0), (10 0, 0 0))') 

It describes a sector with a beginning of 0.0, a radius of 10 degrees (geographical coordinates) and an opening angle of 45 °.

The wrapper, which with additional functions converts it from a true curve to LINESTRING , reduces the accuracy of coordinates and converts it to WKT:

 SELECT ST_AsText(ST_SnapToGrid(ST_CurveToLine(ST_GeomFromText('COMPOUNDCURVE((0 0, 0 10), CIRCULARSTRING(0 10, 7.071 7.071, 10 0), (10 0, 0 0))')), 0.01)) 

gives:

enter image description here

This requires several pieces of pre-computed information (the center position and two adjacent vertices and another point on the edge of the segment), but it has a clear advantage in that it actually creates a really curved geometry. It also works with segments with opening angles greater than 180 ° .

Tip: the 7.071 x and y positions used in the example can be calculated as follows:

  • x = {radius} cos {angle} = 10 cos 45 ≈ 7.0171
  • y = {radius} sin {angle} = 10 sin 45 ≈ 7.0171

Corner Cases: Antimeridian and Pole.

0
source

Source: https://habr.com/ru/post/898832/


All Articles