Select to view content in your preferred language

Python confussion: creating new X,Y coordinates !

1505
4
12-19-2011 04:19 AM
HarrietFoster
Deactivated User
I have a text file like this:
Siteid: 1
Condition: good
X coordinate: 433207.8362 Y coordinate: 4518107.044

Trying to work out a square plot of  20m x 20m for each point and to present the coordinates as a text file !!



# Read entire file and print one line at a time
for line in inFile.readlines():
    nestList = line.split(",")
    id = nestList[0]
    cnd = nestList[1]
    x = nestList[2]
    y = nestList[3]
    outFile.write("Siteid: " + id + "\n")
    outFile.write("Condition: " + cnd + "\n")
    outFile.write("X Coordinate: " + x + "\n")
    outFile.write("Y Coordinate: " + y + "\n")
    outFile.write("\n")
print "the file nests2005 has been read and printed"


# Close the files
inFile.close()
outFile.close()
Tags (2)
0 Kudos
4 Replies
RobertJones6
Deactivated User
What exactly is your question? You mention making a 20m x 20m for each coordinate set, are the given coordinates the centerpoint or one of the corners. Do you need it to write to a polygon? If you give a bit more information and possibly a example of a couple lines from your 'inFile', I'll try to help.

Rob Jones
0 Kudos
HarrietFoster
Deactivated User
From the text file (.csv file) that has been provided (input file), I need to write a script that calculates new x,y coordinates from the coordinates provided in the input file, and write them to a new text file. Assuming that each of the points in the .csv file is the center point of a square-shaped plot that is 20 meters by 20 meters. 

Meaning i would have to write a script that takes the coordinate pairs
from .csv and calculate the lower left corner, lower right corner, upper right corner, upper left corner, based on the centre coordinate pair and output the 4 new coordinate pairs for every center
coordinate pair to a new text file.

The input file contains:
1 good 433207.8362 4518107.044

showing the ID number, description, X coordinate and Y Coordinate.

The code i posted originally extracts this information and creates a list of all different entities and places them into a new text file. Just need to figure out how to work out the 4 new coordinate pairs.

Would it be possible to create a 20m x 20m polygon around the give coordinate pairs and work out the 4 new coordinate pairs from that ?

Many thanks !!
0 Kudos
RobertJones6
Deactivated User
assuming your coordinates are in meters already...
The below should be a good start at getting the bounding corners for a 20m square
...

# replace the x = and y = in your code with this...
x = float(nestList[2]) #convert coordinates from string
y = float(nestList[3]) #convert coordinates from string
xMin = x - 10 # half of the size
xMax = x + 10 # the other half of the size
yMin = y - 10
yMax = y + 10

...

outFile.write('bottomLeft: ' + str(xMin) + ',' + str(yMin) + '\n')
outFile.write('bottomRight: ' + str(xMax + ',' + str(yMin) + '\n')
outFile.write('topRight: ' + str(xMax + ',' + str(yMax) + '\n')
outFile.write('topLeft: ' + str(xMin + ',' + str(yMax) + '\n')


I hope that helps
0 Kudos
HarrietFoster
Deactivated User
Thank you very much, it worked !! 😄
0 Kudos