Creating coordinates for polygon using Python lists

taga

I want to make an algorithm that will create coordinates (corner coordinates) for square polygons. See the picture below:

enter image description here

I have written some code so far, but only for the X-axis, and I think it could be improved.

My desired output should be two nested lists, one for X and one for Y. There should be 25 polygons (5x5):

X_list = [[0, 5, 5, 0], [5, 10, 10, 5], [10, 15, 15, 10], ...]
Y_list = [[0, 0, 5, 5] , [0, 0, 5, 5], [0, 0, 5, 5], ...]

This is the code that I have. How can I make it work, so that it can make polygons on Y-axis too.

max_x = 20
max_y = 20

x = 0
y = 0

xlist = []
ylist = []

lon = []
lad = []
while x < max_x and y < max_y:

    xlist = []
    ylist = []

    x = x
    y = y
    xlist.append(x)
    ylist.append(y)

    x += 5
    y = y
    xlist.append(x)
    ylist.append(y)

    x = x
    y += 5
    xlist.append(x)
    ylist.append(y)

    x -= 5
    y = y
    xlist.append(x)
    ylist.append(y)
    x += 5
    y -= 5

    lon.append(xlist)
    lad.append(ylist)

print(lon)
print(lad)
Deepstop

Here's a simple solution using list comprehensions.

x_count = 5
y_count = 5
step = 5

x_list = y_count * [[i*step,(i+1)*step,(i+1)*step,i*step] for i in range(x_count)]
y_list = [[i*step,i*step,(i+1)*step,(i+1)*step] for i in range(y_count) for j in range(x_count)]

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Comparing two lists of coordinates in python and using coordinate values to assign values

Changing long, lat values of Polygon coordinates in python

Get the coordinates of two polygon's intersection area (in Python)

creating a matrix or a list of lists with python

Creating a report table in Python with nested lists

Creating MultiDimensional Lists during Parsing HTML in Python

How to extract and merge the coordinates using Python?

Creating a loop for creating folders using python

Creating nested lists and pairing them using for loop inline

Qgis: How to export polygon shapefile with coordinates in degrees

GeoMesa: Polygon creation fails with some coordinates

Creating/Using Files with Python 3.6

Creating a python spellchecker using tkinter

Remove outliers from the lists of coordinates

How to subset data using multidimensional coordinates using python xarray?

Creating multiple lines using json file with coordinates in d3.js

Creating and animating a SVG element (using D3.js?) on top of a Leaflet.js map at specific coordinates?

Creating lists in the middle of program

Creating list of lists in a loop

resolved Split list into parallel lists using python

Using grep to compare two lists of Python packages

how to reverse string using lists python

Parsing nested HTML Lists using Python

How to find and save coordinates of squares in chess board using opencv and python

Python: how to save a geotiff file using rasterio with coordinates?

Saving Output Distance From Many Coordinates Using Python For Loop

Python: Computing the distance between two point coordinates using two columns

Merging Polygon Shapefiles in Python

Dynamically creating list in a dictionary using Python