[Closed] how can i create a series of polygons from csv file data
So i have a problem.
I understand some of the ways in which you can access data from a csv file. But how can i create an editable poly or closed spline from a collection of XY coordinates where the xy coordinates are outputted to a csv in the format below? for instance -74.0061245 40.720325 is the first xy vertex position, -74.0053037 40.7199652 is the second xy vertex position and so on. Ordinarily i would access the xyz from seperate columns in the csv. But as some polygons have more vertes than others i need to access them in the below format.
POLYGON ((-74.0061245 40.720325,-74.0053037 40.7199652,-74.0052849 40.7199855,-74.0052796 40.7204734,-74.0053144 40.7204551,-74.0053681 40.7203595,-74.0054351 40.7203067,-74.0055049 40.7202782,-74.0061245 40.720325))
I’ve (hopefully) added a screen grab of the csv format in excel too.
Any advice/ideas?
Thanks,
Paul
All you have left to do is to find a way to fill csv array with string corresponding to each polygon
(
delete objects
polygons = #()
csv = #( "POLYGON ((-74.0061245 40.720325,-74.0053037 40.7199652,-74.0052849 40.7199855,-74.0052796 40.7204734,-74.0053144 40.7204551,-74.0053681 40.7203595,-74.0054351 40.7203067,-74.0055049 40.7202782,-74.0061245 40.720325))" )
for csv_string in csv do (
verts_strings = (dotnetclass "system.text.regularexpressions.regex").matches csv_string "-?\d+\.\d+"
verts = #()
for i=0 to verts_strings.count-1 by 2 do (
append verts [ verts_strings.item[i].value as float, verts_strings.item[i+1].value as float, 0 ]
)
append polygons verts
)
ep = convertToPoly (Editable_mesh())
for verts in polygons do (
indexes = #()
for v in verts do ( append indexes (polyop.createVert ep v) )
polyop.createPolygon ep indexes
)
update ep
select ep
)
Have you looked at this Maxscript tutorial from the help? It should provide information on reading/writing geometry data to a text file.
NOTE: your positions should be stored as a point3 value not a point2 value.
-Eric
Serejah,
Thanks, Your answer is confusing me a little, but i’m no maxscript expert so i’ll try it out and try to understand your answer… Test a few things…
Pixel_Monkey, Yeah i have looked through the maxscript help. I’ve found it useful for doing very simple csv stuff where i get in information i need from a specific column or row. However what i’ve been struggling to understand is how i get maxscrip to understand that all my vert positions are in one cell in the excel sheet. My data comes through as point2 as this information is data that has come out of Qgis as a csv, and thats how it formats the table. Doesn’t give me any optiuons to output the z value… I don’t think. Maybe i’ll look again…
EDIT… I just found a qgis plugin that outputs the coordinates to a better format for the csv, if anyone is interested its called “MMQGIS”
Thanks,
Paul