Hi,
It's the first time using a Python script - so far I just used some statements in the field calculator - and my coding background is small and distant.
I'm using and fiddling a script I saw in another forums but I always get "Parsing error SyntaxError: invalid syntax (line x)" when I add the files I'll use in the script.
I've tried all I read in the tutorials I did and things I googled:
points = “D:\\OneDrive\\Documents\\Tese\\TrabalhoPratico\\Final\\01.gdb\\Lisbon_3D\\Points10”
points = “D:/OneDrive/Documents/Tese/TrabalhoPratico/Final/01.gdb/Lisbon_3D/Points10”
points = open(“D:/OneDrive/Documents/Tese/TrabalhoPratico/Final/01.gdb/Lisbon_3D/Points10”, "w")
I know this is probably really simple... but I'm not getting it with my (it seems) limited google fu.
Cheers
Solved! Go to Solution.
One thing that will not work is using the following line:
points = open(“D:/OneDrive/Documents/Tese/TrabalhoPratico/Final/01.gdb/Lisbon_3D/Points10”, "w")
That's because:
A very important resource to learn about writing information to a featureclass is: Accessing data using cursors—Help | ArcGIS for Desktop . You will need the InsertCursor to write new features or the UpdateCursor to update existing features.
And as Dan is suggesting, please share more of the script you have tried, since that will help us to find out what you are doing wrong.
you will have to post you script that is trying to load the layers
One thing that will not work is using the following line:
points = open(“D:/OneDrive/Documents/Tese/TrabalhoPratico/Final/01.gdb/Lisbon_3D/Points10”, "w")
That's because:
A very important resource to learn about writing information to a featureclass is: Accessing data using cursors—Help | ArcGIS for Desktop . You will need the InsertCursor to write new features or the UpdateCursor to update existing features.
And as Dan is suggesting, please share more of the script you have tried, since that will help us to find out what you are doing wrong.
It was the quotes. *loud doh* I've corrected the ones I had copied from the internet with proper ones.
Thanks for the explanation about text file vs geodatabase.
Thanks to both for the replies!
Glad the comment helped you. I didn't think that was going to be the issue, just wanted to mention it.
I'm sure you are not using the third option to access the data since that would generate the following error:
IOError: [Errno 2] No such file or directory: 'C:\\GeoNet\\writeFeatures\\01.gdb\\Lisbon_3D\\Points10'
Ignore the first part of the path, since it refers to the location on my drive. The error in this case is caused since the folder "Lisbon_3D" does not exist and therefor the text file Points10 cannot be created. The Feature Dataset is not stored as a physical folder in the geodatabase "folder".
There is another tip I would like to share. You showed two ways to store the path to the data:
There is a third way I normally use, which may be faster and that is the raw ("r") notation. If you open the properties of a layer in ArcMap and go to the Source tab, you can copy the path to the data:
I you past it and correct it to "C:\GeoNet\writeFeatures\01.gdb\Lisbon_3D\Points10" you will only have to place an "r" before it to make it a valid path in Python (see line 3). Your options are:
points = "D:\\OneDrive\\Documents\\Tese\\TrabalhoPratico\\Final\\01.gdb\\Lisbon_3D\\Points10" points = "D:/OneDrive/Documents/Tese/TrabalhoPratico/Final/01.gdb/Lisbon_3D/Points10" points = r"D:\OneDrive\Documents\Tese\TrabalhoPratico\Final\01.gdb\Lisbon_3D\Points10"
This might save you some time.
Thanks for the tip.
I've been using the location toolbar in ArcMap to copy and paste. Then adding backslashes. Just adding the r will be quite faster for sure.
Yes I'm using the first option with the corrected quotes. Next time I'll be using the r one.
Grief... your eyes are better than mine...
>>> points = “yup_wrong_quotes_fail” File "<string>", line 1 points = “yup_wrong_quotes_fail” ^ SyntaxError: invalid syntax
To expand on an easy way to get a feature class path. See below.
My second *doh* in this thread. I had look before to the location there and I was "hmm it just shows the name, what a shame", I never remembered to click on it.
Thanks!