POST
|
I am familiar with setting the env.workspace parameter in arcpy. That allows me to work within subfolders of the workspace, eg: layer = arcpy.mapping.Layer("Sub\Test.shp") But how do I do the opposite, ie go up one level in the folder tree? This doesn't work: layer = arcpy.mapping.Layer("..\Test.shp") Is there an easy way to go up a level from the workspace path? Or is it not possible? Thanks
... View more
03-25-2013
08:42 AM
|
0
|
1
|
693
|
POST
|
Oh I see, thanks for pointing that out. Yes, according to this page http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000: There are two basic ways to get and set field values on a row: Using the field name, as in value = row.road_type Using getValue and setValue, as in value = row.getValue("road_type") How incredibly confusing that there's no way to tell if the .property is referring to a field name or a class/property. And what would happen if your field was called 'length'? Which takes precedence, the field name 'length', or the .length property of the Geometry class? How on earth are we meant to differentiate when reading others' code? Very confusing...
... View more
03-06-2013
11:21 PM
|
0
|
0
|
725
|
POST
|
That's interesting, I wonder if this appears in a list of known issues. Either way, thanks for investigating, Brad.
... View more
03-06-2013
06:06 AM
|
0
|
0
|
342
|
POST
|
Thanks Brad. This is really strange. Attached is my script py (also pasted below, as before), it has a blank line at line 3. I copy it from notepad and paste into the Python window. As soon as I paste, the blank lines are gone, see picture (attached) [ATTACH=CONFIG]22395[/ATTACH] The same behaviour occurs when I right click in the Python window to load the py file. Edit -> Past Special... -> Unicode text also does nothing. I'm on 10.0 SP2. Why does this happen for me and my colleagues? Thanks for i in range(4):
print i
print "complete" x
... View more
03-05-2013
11:19 PM
|
0
|
0
|
342
|
POST
|
It is part of the geometry object and is definitely documented. http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000070000000 Thanks for the pointer, but I cannot find any reference to .shape on the page you linked. There is no property of the Geometry class called 'shape'. So, as far as I can see, my original question stands: where is .shape documented? Why does the following work, when the Row class doesn't even have a property called 'shape'? And why is there no object model diagram? It's so difficult to see how classes interact when you have to hop from one help entry to the other. We need a diagram to see how they fit together! >>> cur = arcpy.SearchCursor("Landscan_Sample")
>>> for row in cur:
... print row.shape.extent.XMax
...
-10.8041666667
-10.7958333333
-10.7875
... View more
03-05-2013
11:10 PM
|
0
|
0
|
725
|
POST
|
I was figuring out how to get a dataset's extent via python. In the help entry for extent I was intrigued to note the following sample code snippet: for row in sCur:
geom = row.shape
ext = geom.extent I am unable to find any information in the help files on the .shape class. Can anyone tell me about it? I had thought that you had to do something like this: arcpy.Describe("Layer").extent.xmin ...so I was surprised to see this .shape.extent property. As far as I can see it's undocumented. Where am I going wrong, or where should I look? Thanks
... View more
03-05-2013
05:58 AM
|
0
|
6
|
4655
|
POST
|
Thanks. I should clarify that I'm running my code within the Python window in ArcGIS (as in Geoprocessing -> Python). This is how I always prototype scripts. I find it superior to using an IDE for testing scripts because a) it's easier to reference objects using their names rather than providing full paths, and b) it's useful to see results appear in the map window. You don't get that kind of visual feedback using an IDE. So, given the advantages of using the Python window to execute code, even if that means editing and saving that as a script in another application, how can I get it to stop ignoring blank lines when I paste or load a script? Thanks
... View more
03-05-2013
04:57 AM
|
0
|
0
|
342
|
POST
|
As for your second question, I can't recall ever seeing a traceback with the wrong line number, regardless of the number of blank lines. Where are you seeing this happen? Thanks for your reply. Well I get this behaviour consistently, and it can make it VERY difficult to debug because the Python window (for me, at least) ignores blank lines. Here's a sample script: for i in range(4):
print i
print "complete" x As you can see, there are four lines. It's nice to have blank lines because it helps to organise the code. Naturally there is a deliberate error, and this is what the Python window says: >>> for i in range(4):
... print i
... print "complete" x
...
Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 3) It says the error is on line 3, when we all know it's on line 4. This is because the Python window ignores blank lines, either when you paste them in, or when you right click and choose Load to open a script. This is the behaviour that troubles me because all correspondence between errors and the original script is lost, and that is a bad thing because it's very hard to count lines in your original script editor. Any solutions?
... View more
03-04-2013
02:05 AM
|
0
|
0
|
604
|
POST
|
Thanks everyone. I will be sure to check out some of these programs. So, what is the solution for the annoying problem when debugging in the Python window...when it counts lines by ignoring blank lines, whereas your script editor usually counts line numbers including the blanks? This is a massive usability issue for beginners, when you get a traceback error at line 26 or whatever which doesn't correspond at all to your script in an external editor. Any ideas?
... View more
02-28-2013
11:06 PM
|
0
|
0
|
604
|
POST
|
What is ESRI's 'official' stance for which Python environment to debug in? Pythonwin seems to be advocated, but I've noticed there are others such as pyscripter. Which one offers the best debugging environment? And the best intellisense / autocompletion? I see there is some guidance here http://blogs.esri.com/esri/arcgis/2010/09/14/review-of-ides-for-python/ but I really think that ESRI needs to take a more proactive stance here, because Python adoption is surely premised on the quality of the tools that we can use to debug, which at the moment is nowhere near as easy as say VBA or Visual Studio.
... View more
02-28-2013
02:25 AM
|
0
|
16
|
1325
|
POST
|
Thanks for your helpful replies. It's an aside, but I think that having a function called the same thing as a class is just plain confusing. Search the help files for Layer and you'll see two entries, if you're a beginner it's difficult to make sense of that. It's just not user friendly because you have two entires with the same name. Anyway, thanks for the info
... View more
01-14-2013
04:11 AM
|
0
|
0
|
338
|
POST
|
And come to think of it, it's ridiculous that ESRI used the name Layer for the function when they also have a massive class called Layer. Surely someone could have thought of a different name for the function to avoid this ambiguity???
... View more
01-10-2013
11:40 PM
|
0
|
0
|
338
|
POST
|
Is it just me, or is the help entry for arcpy.mapping.Layer() quite misleading? It gives the distinct impression that you can only use this function on .lyr files, but actually you can pass a shapefile as a path and it works just fine. So why does it imply that you can only reference a layer file (.lyr) as opposed to a map layer which could be one of any number of formats? Does anyone else agree that this entry could be clearer?
... View more
01-10-2013
11:26 PM
|
0
|
4
|
828
|
POST
|
When I use the regular pan/zoom tools or Data Driven Pages, ArcGIS correctly updates my scale bar according to the way I set it. But when I alter a map layout's extent using the DataFrame.scale property, perhaps preceded by DataFrame.zoomToSelectedFeatures(), my scale bar gets messed up, see the image below. The top image shows the scale bar correctly resized; the bottom image shows what happens when I alter zoom in Python via the DataFrame class. [ATTACH=CONFIG]20062[/ATTACH] So what gives? Is this a bug? Is there some kind of refresh procedure that I can use to ensure that my scale bar is resized properly when using Python to batch export maps? FYI, my scale bar is set to 'Adjust Division Value' when resizing...
... View more
12-19-2012
12:29 AM
|
0
|
1
|
918
|
POST
|
I'm trying to figure out the 'established' methodology for the following: a colleague of mine has some population data for Russia. The data are supplied in WGS84 with each cell equal to 0.0083333333 of a unit, where the angular unit is degrees. I believe that fraction is a 0.5 x 1/60th of a degree, so half a minute, or 30 arc seconds. We want to create a projected grid around each point to do some analysis on the data. Ideally we want a 1km grid. That means we have a mismatch between a projected grid and the population data in geographic. How best to proceed? What projection should I use for Russia? It strikes me as too big to use a single projection, so perhaps we need to reduce our study area extent, and then reproject the original data to the new grid. Since our data represent population, do I need to worry about what happens behind the scenes during the reprojection? Ie, if two old GCS cells fall within one new projected cell, should I take the sum or the mean? Presumably if we want the total population between the unprojected and projected datasets to be the same, we need to take the sums of values during reprojection, thus preserving the total. But I'm not 100% sure. If anyone can help me figure out what normally happens when transforming between GCS and PCS that would be extremely helpful. Thanks
... View more
08-08-2012
01:38 AM
|
0
|
0
|
531
|
Title | Kudos | Posted |
---|---|---|
1 | 01-20-2012 05:38 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|