|
POST
|
Thanks for that, I also found a part in the traceback that had that issue:
thisLogger.error(' Line %i' % tb.tb_lineno)
thisLogger.error(' ' + str(e.args[0]))
I would still consider myself a novice at Python, but you only get better through trying, learning, and asking right. This is my first time attempting logging as well. My traceback error is now gone, but here is what I am getting now (see attached image). When I look at the Python in Notepad ++ line 90 is this section:
with open(rapLogFile, 'r') as f:
lines = f.read().splitlines()
f.close
for line in lines:
thisLogger.info(' ' + line)
thisLogger.info(' ')
Did you attempt to set line to string values?
thisLogger.info(' ' + str(line))
... View more
05-20-2013
12:32 PM
|
0
|
0
|
2857
|
|
POST
|
The error is telling you exactly what is wrong: you are trying to concatenate an Integer and a string. Likely values in "line" are coming across as integers
with open(rapLogFile, 'r') as f:
lines = f.read().splitlines()
f.close
for line in lines:
thisLogger.info(' ' + line)
thisLogger.info(' ')
Change to:
with open(rapLogFile, 'r') as f:
lines = f.read().splitlines()
f.close
for line in lines:
thisLogger.info(' ' + str(line))
thisLogger.info(' ')
... View more
05-20-2013
12:00 PM
|
0
|
0
|
2857
|
|
POST
|
For the purposes of discussion, building a Topology is not an option, otherwise this exercise would be easy. I am performing the same Select By Location two different ways. The first method, let's say Method A, is performed manually, using the Select By Location icon in ArcMap. I am selecting line features from LayerL that intersect point features from LayerP. A review of the selection seems to indicate that results are accurate and expected. The second method, let's say Method B, is performed via a Python script. Below is a code snippet lyrL = arcpy.GetParameterAsText(0)
lyrP = arcpy.GetParameterAsText(1)
arcpy.SelectLayerByLocation_management(lyrL, "INTERSECT", lyrP, "", "NEW_SELECTION") Method B does *NOT* return the same selection as Method A. The results of this selection are dubious, as many line features are not selected that do, in fact, intersect points, as well as many line features that are selected that do NOT intersect points. I am thinking this might be a tolerance issue, but I can't find anything to support my theory. Anybody have an idea why this is, or has anybody experienced this before? Are both lyrL and lyrP in the same spatial reference? (just a hunch and something to dbl-chk)
... View more
05-16-2013
04:12 AM
|
0
|
0
|
1029
|
|
POST
|
Glad to hear this is resolved and just as an fyi.... I noticed your output location is C:\ drive --- have you attempted write to a network location yet? You might run into new problems, in which case you might try to set your output to a File Geodatabase --- this has resolved much of our issues from a similar implementation.
... View more
05-15-2013
11:40 AM
|
0
|
0
|
2846
|
|
POST
|
There is a way to access ArcObjects from python. There is a Stack Exchange thread titled: How do I access ArcObjects from Python? http://gis.stackexchange.com/questions/80/how-do-i-access-arcobjects-from-python that gives some leads on this. It IS, however, both exasperating and annoying to keep hearing things along the lines of "python scripting is not intended to do things like <fill in simple task here>". eeew. heh -- thanks for the info, I will take a stab at it! j
... View more
05-15-2013
11:29 AM
|
0
|
0
|
387
|
|
POST
|
All "CURRENT" means is that your code is referencing the document that is currently loaded into the ArcMap application. This means the code is being run from either the Python window or from a script tool from within ArcMap. The document that is open should have all your extra stuff, often times tucked away off the page. Your code can call it when/if needed. Jeff Yes, I understand. The problem I am running into is the Python Add-In I am developing must be agnostic to any specific .mxd document. I just need the tool to place a text element onto the Layout, especially if it is just an "Untitled.mxd" / vanilla .mxd that has nothing loaded and was just opened. Thanks again! j
... View more
05-15-2013
07:40 AM
|
0
|
0
|
3226
|
|
POST
|
At 10.1 we added graphic element and text element cloning. If you have a pre-authored text element in your layout, then you can clone it an place it as many times as you need. Jeff Jeff -- I think I understand this now. From my other thread in the Python forum, I was under the impression that cloned elements could be added to different/new .mxd documents. From what you mention above, this sounds like it is not possible with the arcpy.mapping module and this functionality is limited to within a single .mxd and with elements that already exist. That is, I cannot add new elements to any .mxd and I cannot add cloned elements from one .mxd to another. Thanks, james
... View more
05-15-2013
05:28 AM
|
0
|
0
|
4193
|
|
POST
|
Clone() is a method on the text element or graphic element classes. Check out the second example on the graphic element class. It builds a dynamic table by cloning graphic lines and text. http://resources.arcgis.com/en/help/main/10.1/#/GraphicElement/00s300000040000000/ Jeff Jeff, I took a look at the example but I'm not understanding how this can help. Now, I can setup an .mxd with all of the elements I need, and yes i can clone them, but how am I supposed to use these in the "CURRENT" mxd document? That is, I still cannot add any graphic or text element to a map document. (or can I and I am missing something from the example?) To be clear: just how can the Clone() method help me to add TextElements to a totally vanilla (aka, "CURRENT") .mxd? Thanks! James
... View more
05-14-2013
11:18 AM
|
0
|
0
|
3226
|
|
POST
|
I think this would be the "best" way. Since it's a point you could also use the .centroid property (and some other ones too). partObj = wgs84PntGeom.getPart(0)
partObj.X
partObj.Y So, just to clarify - probably best not to parse the JSON... I just put that in there to illustrate it was returning WGS84 coordinates. Understood. Although that JSON string is fast enough to print out for the onMouseMoveMap event as the user moves across the view! Thanks again
... View more
05-13-2013
12:31 PM
|
0
|
0
|
1410
|
|
POST
|
Can you suggest how to parse out the actual x/y values out of that JSON string? Pretty simple to do:
data = json.loads(wgs84PntGeom.JSON)
wgsX = data["x"]
wgsY = data["y"]
print "X:" + str(wgsX) + " Y:" + str(wgsY)
... View more
05-13-2013
12:07 PM
|
0
|
0
|
1410
|
|
POST
|
I think you want GCS_WGS_1984 = 4326 (on page 18). I messed around with it and it seems to work for me like this: pntObj = arcpy.Point(X= 12345,Y=6789)
inSr = arcpy.SpatialReference(2927) #NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet
outSr = arcpy.SpatialReference(4326) #GCS_WGS_1984
pntGeom = arcpy.PointGeometry(pntObj, inSr)
wgs84PntGeom = pntGeom.projectAs(outSr, "NAD_1983_HARN_To_WGS_1984_2") Which yields: >>> wgs84PntGeom.JSON u'{"x":-126.81813166550971,"y":45.173061523748544,"spatialReference":{"wkid":4326}}' Thanks for this -- once I figured out my inSr WKID, it returns the lat/lon correctly. I went ahead and made your post the answer, but... Can you suggest how to parse out the actual x/y values out of that JSON string? Thanks again for your help. j
... View more
05-13-2013
11:32 AM
|
0
|
0
|
1410
|
|
POST
|
Just use the integer (don't format as string): projectedPoint = ptGeometry.projectAs(12345, 54321) Thanks again... From the geographic_coordinate_systems.pdf (pg 35) the WKID for "WGS_1984" = 7030 From the geographic_transformations.pdf (pg 66) the WKID for "NAD_1983_HARN_To_WGS_1984_2" = 1900 Here's the updated code only using the WKID's:
lyr = arcpy.mapping.ListLayers(mxd)[0]
dsc = arcpy.Describe(lyr)
spref = dsc.spatialReference
lpoint = arcpy.Point()
lpoint.X = x
lpoint.Y = y
ptGeometry = arcpy.PointGeometry(lpoint, spref)
projectedPoint = ptGeometry.projectAs(7030, 1900)
prjX = projectedPoint.X
prjY = projectedPoint.Y
print "X:" + str(prjX) + " Y:" + str(prjY)
Here's the output error: projectedPoint = ptGeometry.projectAs(7030, 1900) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 761, in projectAs return convertArcObjectToPythonObject(self._arc_object.ProjectAs(*gp_fixargs((spatial_reference, transformation_name)))) RuntimeError: Object: CreateObject error creating spatial reference
... View more
05-13-2013
10:16 AM
|
0
|
0
|
3094
|
|
POST
|
It makes the code a bit harder to comprehend, but how about using the WKID (well known id) for your projections and transformation definitions? I have notices some "discrepencies" in the naming conventions, and well, computers like numbers, right? I just pull the codes from these documents: C:\Program Files (x86)\ArcGIS\Desktop10.1\Documentation\geographic_transformations.pdf C:\Program Files (x86)\ArcGIS\Desktop10.1\Documentation\geographic_coordinate_systems.pdf C:\Program Files (x86)\ArcGIS\Desktop10.1\Documentation\projected_coordinate_systems.pdf Thanks for your input! I attempted to set a WKID value but end up with the same error: projectedPoint = ptGeometry.projectAs(to_sr, r'1900') File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 761, in projectAs return convertArcObjectToPythonObject(self._arc_object.ProjectAs(*gp_fixargs((spatial_reference, transformation_name)))) ValueError: 1900
lyr = arcpy.mapping.ListLayers(mxd)[0]
dsc = arcpy.Describe(lyr)
spref = dsc.spatialReference
lpoint = arcpy.Point()
lpoint.X = x
lpoint.Y = y
ptGeometry = arcpy.PointGeometry(lpoint, spref)
to_sr = arcpy.SpatialReference('WGS 1984')
projectedPoint = ptGeometry.projectAs(to_sr, 1900) #<--attempted with both integer value and r'1900'
prjX = projectedPoint.X
prjY = projectedPoint.Y
print "X:" + str(prjX) + " Y:" + str(prjY)
The from system is NAD83 HARN Florida East FIPS 901 Feet, so perhaps my ignorance on the details for these coordinate conversions is just completely the cause here.
... View more
05-13-2013
10:05 AM
|
0
|
0
|
3094
|
|
POST
|
The fact an input shapefile is being used shouldn't be relevant. As long as you get a pointgeometry object somehow with a defined spatial reference the projectAs should work fine. Your first solution shouldn't have any issue other than something being wrong with your transformation parameter (r'NAD_1983_HARN_To_WGS_1984'). I get your same error if I use the shapefile and your transformation. The samples I provided were simplified to use shapefiles to eleminate the rest of the code as being an issue. Tim -- I tried the code below but getting the same error for the transformation: line 217, in onMouseDownMap projectedPoint = ptGeometry.projectAs(to_sr, 'NAD_1983_To_NAD_1983_CSRS_4 + NAD_1983_CSRS_To_WGS_1984_2') File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 761, in projectAs return convertArcObjectToPythonObject(self._arc_object.ProjectAs(*gp_fixargs((spatial_reference, transformation_name)))) ValueError: NAD_1983_To_NAD_1983_CSRS_4 + NAD_1983_CSRS_To_WGS_1984_2 Code:
lyr = arcpy.mapping.ListLayers(mxd)[0]
dsc = arcpy.Describe(lyr)
spref = dsc.spatialReference
lpoint = arcpy.Point()
lpoint.X = x
lpoint.Y = y
ptGeometry = arcpy.PointGeometry(lpoint, spref)
to_sr = arcpy.SpatialReference('WGS 1984')
## fails on this line
projectedPoint = ptGeometry.projectAs(to_sr, 'NAD_1983_To_NAD_1983_CSRS_4 + NAD_1983_CSRS_To_WGS_1984_2')
prjX = projectedPoint.X
prjY = projectedPoint.Y
print "X:" + str(prjX) + " Y:" + str(prjY)
... View more
05-13-2013
09:53 AM
|
0
|
0
|
3094
|
|
POST
|
The fact an input shapefile is being used shouldn't be relevant. As long as you get a pointgeometry object somehow with a defined spatial reference the projectAs should work fine. Your first solution shouldn't have any issue other than something being wrong with your transformation parameter (r'NAD_1983_HARN_To_WGS_1984'). I get your same error if I use the shapefile and your transformation. The samples I provided were simplified to use shapefiles to eleminate the rest of the code as being an issue. Understood -- I will re-work the original attempt. Thanks again, j
... View more
05-13-2013
09:40 AM
|
0
|
0
|
3094
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|