|
POST
|
Never mind about where to place those three methods. I see now that based on your code, it's outside the for loop. Thanks.
... View more
07-17-2018
11:56 AM
|
0
|
2
|
2641
|
|
POST
|
Hi Randy, Apologies for the late reply. Appreciate the suggestions. My original map (ie "mxd" from my original code) contains existing text elements representing towns, as well as text elements for watershed names and the ESRI service credits (which apparently are text elements, too). Because I move the text elements to a different geographic location, all I really want to do is create 5 new text elements in the new map (ie "copy_mxd" from my original code) that are the five towns in the "pop_cent" variable in the code. I was hoping I could just take one text element from the original map and iteratively copy and replace it with the 5 towns from the pop_cent tuple, while moving it to a different geographic location. I would end up with 5 next text elements in the new map with town names. I haven't heard the idea of naming text elements before so I will give that a try. Where do you suggest I put the "RefreshTOC", "RefreshActiveView", and "save" methods, inside or outside the for loop on line 16? Thank you!
... View more
07-17-2018
11:41 AM
|
0
|
0
|
2641
|
|
POST
|
Hi Darren, Sorry for late reply. I put your suggestion near the end of my script, outside of the for loop on line 16. I'm guessing you're suggesting I put it inside the for loop? Also, I should note that I apply the .save() method to the "copy_mxd" map document. Thank you!
... View more
07-17-2018
11:21 AM
|
0
|
0
|
2641
|
|
POST
|
I've read just about every post on the internet about updating and/or adding TextElements using arcpy. I am not able to get the text in my TextElement object to update. The portion of my script is: pop_cent = ('Harrisburg', 'Middletown', 'Hershey', 'Halifax', 'Elizabethville')
if os.path.exists(newpath) == False:
mxd = arcpy.mapping.MapDocument(inpath) #Create map document object using basemap
mxd.saveACopy(newpath) # Copy the basemap from Adams for adding appropriate data
copy_mxd = arcpy.mapping.MapDocument(newpath) # Create map document object using copied basemap
df = arcpy.mapping.ListDataFrames(copy_mxd, "Layers")[0] #lists the dataframe object to use in AddLayer
x = df.elementPositionX
print x
y = df.elementPositionY
print y
orig_text = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
for d, pop in enumerate(pop_cent):
orig_text[d].text = pop_cent[d]
print(orig_text[d].text)
orig_text[d].elementPositionX = x
orig_text[d].elementPositionY = y
arcpy.RefreshActiveView()
The script successfully moves the TextElement to where I want in the "copy_mxd" and the print statement in line 18 provides the correct string from pop_cent. But, the actual TextElement's text does not update the text. Why? Based on what I've read online, is it because not all the TextElements are embedded in a focused dataframe? Or perhaps I'm trying to go between two different map documents (mxd and copy_mxd) with TextElements? Or do I need to somehow access the LayoutView using the mapping module? Thank you, Josh PS Using ArcMap 10.4 on Windows 7, Python 32-bit.
... View more
07-11-2018
12:45 PM
|
0
|
9
|
2820
|
|
POST
|
Ok, thanks for following up Allison. I use 10.4, too. I sort of follow what Gerry said but I'm struggling to translate it into automated Python code. In essence, I believe he is getting each of the elements' extent from the layout view using arcpy.mapping classes (ie GraphicsElements, DataFrame, TextElements, etc). That may take some math in python to calculate the extent values (xy min/max) if you are using any other layout element besides DataFrame (LegendElement, TextElement, etc.). DataFrame has an "extent" property from which you can get xmin, xmax, ymin, ymax values. If using other elements, you would have to calculate those values using the elementHeight, elementWidth, elementXPosition, and elementYPosition properties. Then, I suppose he is cropping the original exported image using PIL's (Python Image Library) "crop" method, which requires four pixel coordinates values- left, upper, right, lower. I've never used PIL, so I'm not familiar enough with what properties (xmin, xmax, ymin, ymax) from the mapping class equal what pixel coordinates from PIL crop method. Also, I'm not sure if the properties (xmin, xmax, etc) from ArcGIS mapping, which are in map units, can easily be inputted into PIL's crop method without first undergoing some type of conversion to get them into pixel coordinates. Plus, I'm not sure what the units of the original exported image (in my case, a JPEG with unwanted white space) are! If they aren't correct in pixel coordinates, then you'd have to convert them so crop method works properly. That's probably more confusing than helpful, but I was basically thinking off the top of my head in hopes it was useful for you. It would be nice to have Gerry's input, but I don't think he's even logged into GeoNet for quite some time...
... View more
06-27-2018
09:23 AM
|
0
|
1
|
3639
|
|
POST
|
Hi Allison, I realize this is an old post, but did you ever get any traction on this? I have a similar issue. I would like to export hundreds of layout view grouped graphics as a JPEG for use in a Word Doc. I don't want any white space surrounding my exported map. Thank you for any help you might be able to provide! Sincerely, - Josh
... View more
06-27-2018
08:13 AM
|
0
|
3
|
3639
|
|
POST
|
I realize this is an old post, but not a whole lot on the internet on this topic besides this post. Has the ability to "Clip Output to Graphics Extent" via arcpy been added to recent version of ArcMap (I have 10.4)? I have hundreds of map documents I'd like to export as JPEGs to insert into Word documents and this would be so helpful. I don't want the white space around the map document, just the graphic. Based on my research, I have a sinking feeling it has not been added... Jeff. Would it be possible for you to explain in more detail how to duplicate this function using arcpy in combination with mask layers/definition queries? I'm struggling to understand that idea at a conceptual level, let alone a scripting level. Thank you!! - Josh
... View more
06-27-2018
08:05 AM
|
0
|
0
|
527
|
|
POST
|
Hi Stuart, I realize this is a rather old post, but I am working with the daily NWS AHPS Stage III QPE data in shapefile format (pre-March 2017). While I really appreciated your reply (especially helpful in clarifying HRAP meaning), I am still unsure of how to best convert the shapefile points into a raster in ArcGIS based on your reply. I've tried using the "Feature to Raster" GP tool on one shapefile. I get huge grids, something on the order of 33 x 33 km (maybe that's appropriate?). Focusing on option 3, I'm trying to understand what you mean by "set the cell size against the full range of the AHPS HRAP data set" using the "nws_precip_allpoint_tar" shapefile. How can a vector file have a cell size? Are you just referring to setting the extent of the vector to raster conversion tools in the Environment settings to the allpoint shapefile? Or, is it the cell size taken from the allpoint that's been converted to a raster? If so, do you just use the Feature to Raster Tool and leave the default cell size? Otherwise, re-projection of raster and intersection with vector data seems straightforward. I'm just confused on the best way to convert these shapfiles in a rather obscure projection to a raster useful in analysis. Thanks!! - Josh
... View more
05-30-2018
12:48 PM
|
0
|
0
|
7665
|
|
POST
|
Also, another thought I had that maybe caused this error was the length of my Esri grid raster object names or paths. I would've anticipated a "000878" or "000161" error if that were the case though. Plus, most of the names of my outputs in all my other fgdb's are longer than 13 characters and I had no issues/crashes except at this mosaic to new raster step. Is it possible I just got lucky with some of my successful iterations? In any case, here's a good reminder on Esri GRID formats and names: Output raster formats and names—ArcGIS Help | ArcGIS Desktop
... View more
05-04-2018
06:04 AM
|
0
|
0
|
3020
|
|
POST
|
Thanks Dan! Your post included data storage concepts and recommendations I've not heard of before. I'm using ArcGIS for Desktop, but I assume the organizational concepts are transferable. In any case, having a clean and Pythonic "friendly" file structure is something I'm learning is vital for script performance. Hard to always know how to build file structures within Arc without issues/crashes, so the post is helpful! I've typically operated under the impression that all data types (both raster or vector) should be stored in some type of native Esri storage database. From experience, I know vector data is often better stored in fgdb, but haven't done extensive Pythonic raster analysis in Arc until now. Since I will likely share the raster data and want to generally get better at Pythonic raster analysis inside and outside of ArcGIS products, knowing that .tif or numpy array storage is likely a superior storage format is helpful. Thanks for tips! Unfortunately, I don't think I can quite mark as correct, since I'd need to rewrite my script and transform all my data entirely to confirm if file structure/data format is the root cause of my original problem. But, I happily mark as helpful and I think others who have a similar crash can likely avoid hard to debug headaches by using your organizational strategy!
... View more
05-04-2018
05:35 AM
|
1
|
0
|
3020
|
|
POST
|
Thanks for the reply Dan. Interesting thought about the file and folder constructs. Raster objects include the file path and don’t have extensions if they are stored in file geodatabases, right? My general data structure strategy was to already have file geodatabases created for each step in my script that generated output data. Then, as I move along in my script, I use arcpy.env.workspace to change the workspace to the file geodatabase where I save the raster object output. It was my attempt at keeping very organized in my definition of path variables early on in my script. May be a bad strategy but without rewriting my whole script not sure how to avoid it at this point... Do you suggest that I include all optional parameters even those I don’t want to use? In my case, I suppose would have “ “ for the mosaic colormap mode parameter. I will try the repair as a more last resort option but thanks for the heads up. Thanks again!
... View more
05-03-2018
06:48 PM
|
0
|
1
|
3019
|
|
POST
|
Hello, I keep getting the following error when I run my script in IDLE: While I believe it is hard to isolate the specific error that causes Python to crash like this (any tips doing that are appreciated!), I've isolated the line of code where the Python crash seems to happen: arcpy.MosaicToNewRaster_management([stream_mask,sqr_mask],strm_rd_combo,mosaic,"","64_BIT","3.2","1","SUM") I cannot share the entire code. The inputs are masked rasters representing elevation data with "sqr_mask" purposely having very large data values. Also, they are raster objects which have been saved to disk. All other input parameters seemingly line up with the input rasters' properties. The funny thing is I've run other similar datasets from different geographic areas/extents and the code completes without any errors. When I try running the datasets that caused Python to crash in ArcMap instead, sometimes the Mosaic to New Raster tool just stops working and doesn't progress/freezes. It causes me to restart ArcMap. Once I restart, I try the tool again using the same rasters and it will complete successfully. I've tried the following in my script and in ArcMap to avoid getting the script error or tool freezing to no avail: 1) Using Int on the input rasters to reduce potential memory issues 2) Adjusting input parameters- especially mosaic type and pixel type 3) Making the extent of one of the input rasters the extent of the mosaic to new raster tool in the environment settings in script. 4) Switching the order of the input rasters. 5) Restarting and shutting down my machine. My thinking is there may be a more significant issue with my Python installation. Maybe some .dll file not installed properly or a path variable that is missing/included that's causing the crash. As this has been extremely frustrating, any help or pointing in the right direction would be very much appreciated. - Josh
... View more
05-03-2018
12:48 PM
|
0
|
5
|
3343
|
|
POST
|
Hi Curtis, thanks again for taking the time to answer my inquiries. I don't script regularly in Python and pretty new to creating script tools. Getting insight from an expert is helpful in my understanding of setting parameters, something I've struggled to understand. It was indeed my missing "nodata_value" parameter. Should have been helped by the error I was getting (Error 000800: The value is not a member of ClippingGeometry | None). I guess I was thinking this error was generated because one of my input parameters (buffout or outrast) was an output of a previous tool and had to be set (by using SetParameterAsText and creating a parameter with Type "Derived") as an input parameter in my final clip_management step. I see now that SetParameterAsText is not exactly relevant to my situation because my datasets are previously set as parameters (using GetParameterAsText()) and therefore, the script can call any of them as arguments (ie parameters) in gp tools later on in the script. One final question, if you don't mind. Can you point me to helpful resources on tips to reduce the number of overall parameters in a tool dialog for intermediate data? I think wanting fewer parameters on this script tool's dialog also played into my attempted use of SetParameterAsText(). Marked your answer as correct. Thanks again!!
... View more
03-26-2018
05:53 AM
|
0
|
1
|
3641
|
|
POST
|
Thanks for responding Curtis. I really appreciate you taking the time to help me understand this concept. It's starting to get clearer but I think I need to circle back around for clarity's and organization's sake (for myself and others in geonet community). Here is an re-arranged version of my full code for the original python script behind script tool that keeps giving me errors. Hopefully it clarifies my end goals: # Set up parameters for script tool
inrast = arcpy.GetParameterAsText(0)# File path to original raster clipped to study area
outrast = arcpy.GetParameterAsText(1) #File path to raster that's been clipped to study area
outext = arcpy.GetParameterAsText(2) # Feature class used as the study area to which raster and streams are clipped
infc = arcpy.GetParameterAsText(3) # Input stream feature class to be clipped to study area
outfc = arcpy.GetParameterAsText(4) # Output clipped stream feature class
buff_dist = arcpy.GetParameterAsText(5) # Input Buffer distance parameter
buffout = arcpy.GetParameterAsText(6)# Output buffered stream feature class parameter
outpath = arcpy.GetParameterAsText(7) # Output raster dataset (raster clipped to buffered stream polys) parameter
# Add Message
arcpy.AddMessage("Starting clipping analysis...")
# Run the Clip management Tool on Raster
arcpy.Clip_management(inrast, "", outrast, outext, "", 'ClippingGeometry', 'NO_MAINTAIN_EXTENT')
arcpy.AddMessage("Raster clipping to study area successful!")
# Run the Clip analysis Tool on Vector Stream lines fc
arcpy.Clip_analysis(infc, outext, outfc)
arcpy.AddMessage("Vector clipping to study area successful!")
# Run the Buffer Analysis tool on clipped stream (outfc)
arcpy.Buffer_analysis(outfc, buffout, buff_dist)
# Add a success message
arcpy.AddMessage("Buffer of streams successful!")
# Run the clip tool on hillshade using the output buffer fc
arcpy.Clip_management(outrast, "", outpath, buffout, "ClippingGeometry", 'NO_MAINTAIN_EXTENT')
# Add a success message
arcpy.AddMessage("Clipping of hillshade to buffer output successful!") As you can see, I'm not using any derived parameters in this script- just required output and input parameters. I get the first clipped raster, the clipped stream feature class, and the buffered stream polygon feature class into a file geodatabase. But every time I've run this tool, it gives me an error for the final Clip step. I understand that derived parameters don't show up in tool dialog and that it's most effective to put them at end of parameters for organizational purposes. Not exactly clear how to follow your suggestion of setting path of buffout. Would calculate the path of buffer output look something like this?: buffpath = os.path(buffout) Then I'd use arcpy.SetParameterAsText(): arcpy.SetParameterAsText(8, buffout) Finally, input the above into Clip Management tool: arcpy.Clip_management(outrast, "", outpath, buffpath + buffout, "ClippingGeometry", "NO_MAINTAIN_EXTENT") Also, would I be able to set other outputs from tools (ie outfc, outrast) as inputs using SetParameterAsText()? Again, much thanks for your help Curtis! Josh
... View more
03-24-2018
12:34 PM
|
0
|
3
|
3641
|
|
POST
|
Thank you for your reply Curtis and for the tip about "" vs "#"! I'm still not getting it, sorry. I do understand that I need to change an output parameter used as input to a "Derived" Type. But, in general I'm still not understanding this concept and honestly, Esri''s help documents are not very clear on this topic in my opinion. The output parameter I'd like to use as an input parameter is actually "buffout", not "outrast". This "buffout" variable is the output parameter of arcpy.Buffer_management a few steps earlier in my script, something similar to: buffout = arcpy.GetParameterAsText(5) # Feature class output of buffer analysis- DO I GET RID OF THIS STEP??
buff_dist = arcpy.GetParameterAsText(6) # Buffer distance parameter
# Run the Buffer Analysis tool on stream feature
arcpy.Buffer_analysis(outfc, buffout, buff_dist)
try:
# Add Parameters
outrast = arcpy.GetParameterAsText(7) # Output raster dataset clipped to stream buffer polygons
# Run the clip tool on hillshade using the buffout feature class
#arcpy.SetParameterAsText(8, buffout) IS THIS CORRECT PLACEMENT??
arcpy.Clip_management(outpath, "", outrast, buffout, "ClippingGeometry", 'NO_MAINTAIN_EXTENT')
If I want "buffout" from this earlier arcpy.Buffer_analysis step- line 1- as an input in the Clip_management step- line 13-, I'm assuming I'd use arcpy.SetParameterAsText(8 (or whatever next correct index is...), buffout) somewhere in my code, but where? Also, when I set the "buffout" parameter as "Derived" in script tool properties, why does it not show up as a parameter when opening my script tool? Thanks again!!
... View more
03-19-2018
06:30 PM
|
0
|
5
|
3641
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2018 02:06 PM | |
| 1 | 05-04-2018 05:35 AM | |
| 1 | 08-10-2018 06:03 AM | |
| 1 | 02-13-2018 12:33 PM | |
| 1 | 07-20-2017 08:46 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|