Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Generate grid line coordinates

User_1871Jun 14 2022 — edited Jun 14 2022

Edited:
Oracle 18c:
Using an SQL query, I want to generate a list of coordinates that make up the line segments of a square grid graph:

<img src="https://objectstorage.us-phoenix-1.oraclecloud.com/p/BqK85Rn1zA5MP0vYiqbAdPgs7Z6OmMxw8SD3WCFVm5kY8uReidZ1KPIKkgJ1hCkG/n/axciphqpnohg/b/forums-legacy/o/uploads/60ONNU0L1KRF/image.png" alt="image.png">STARTPOINT_X STARTPOINT_Y ENDPOINT_X ENDPOINT_Y
------------ ------------ ---------- ----------
           0            0          1          0 --horizontal lines
           1            0          2          0
           2            0          3          0
           3            0          4          0
           4            0          5          0
           5            0          6          0

         ...

           0            0          0          1 --vertical lines
           0            1          0          2
           0            2          0          3
           0            3          0          4
           0            4          0          5
           0            5          0          6

         ...

[220 rows selected]

Details:
The lines would be split at each intersection. So, in the image above, there are 220 lines. Each line is composed of two vertices.
Ideally, I would have the option of specifying in the query what the overall grid dimensions would be. For example, specify this somewhere in the SQL: DIMENSIONS = 10 x 10 (or DIMENSIONS = 100 x 100, etc.).
To keep things simple, we can assume the grid's overall shape will always be a square (length = width).
I've supplied sample data in this db<>fiddle. I created that data using Excel.
Hint: The vertical grid lines start at row 111.
The reason I want to generate this data is:
I want sample line data to work with when testing Oracle Spatial queries. Sometimes I need a few hundred lines. Other times, I need thousands of lines.
Also, if the lines are in a grid, then it will be obvious if any lines are missing in my results (by looking at the data in mapping software and spotting gaps).
How can I generate those grid line coordinates using Oracle Spatial?

This post has been answered by John OToole (Dublin) on Jun 14 2022
Jump to Answer

Comments

John OToole (Dublin)
Answer

I've attached a script below which I use to create grids of lines or polygons. There are there variations, the first creates an orthoganal grid of lines not split at each junction, the second creates an orthoganal grid of lines split at each junction, the third create an orthoganal grid of polygons.
There probably is a way of doing this in a single SQL statement, but these examples are just using PL/SQL anonymous blocks.
Cheers,
John
create_grids.txt (6.32 KB)

Marked as Answer by User_1871 · Jun 24 2022
User_1871

[John OToole (Dublin)](/ords/forums/user/John OToole (Dublin)) Thanks!

1 - 2

Post Details

Added on Jun 14 2022
2 comments
133 views