Re: [Tutor] ArcGIS Create a python script to generate north-facing aspect raster from digital elevation model
On Mar 21, 2015 1:22 AM, Michael Omohundro momohund1...@yahoo.com.dmarc.invalid wrote: Does anyone know how to create a python script to generate an aspect raster from the input elevation in a digital elevation model? This topic is out of the normal scope of the mailing list. It's hard to say if you are having a python issue or an ArcGIS issue. I could possibly help with the latter, but please provide the trace back you get when it errors out, or how the output differs from what you expect. Without the data you are using I'm not going to attempt to run your code. I need to specify TWO variables as user parameters: input elevation and output north-facing aspect. I need to create an aspect raster from the input elevation from a digital elevation model. I need to find the north facing aspect is the trick, between 0 and 22.5 and between 337.5 – 360. These are the north facing elevation ranges. I need to reclass the north facing aspect into a 1/Nodata raster. Any cell is north facing should have value 0, other cells should be NoData. I need to save the results as a permanent raster named as my second input parameter. I can't use ModelBuilder then convert it into Python script. Here is what I have so far: # Created on: March 20 2015 # Usage: lab03-5 Aspect from raster surface # Requirements: ArcGIS Desktop and Spatial Analyst Extension # --- # Import system modules import arcpy from arcpy import env from arcpy.sa import * In my experience this makes debugging harder, I can't tell if you are using local functions or module functions without a detailed knowledge of the module you imported. arcpy.env.overwriteOutput = True # Set environment settings. dem30 is the digital elevation model that holds the elevation data. elevation = rF:\NW_Missouri_State_University\_Python_Class\Week_10\lab10\dem30 # North facing elevation 1, range 0 to 22.5 inRange_North1 = range (0, 22.5, 0.5) #North facing elevation 2,range 337.5 - 360 inRange_North2 = range (337.5, 360, 0.5) # Set local variables inRaster = elevation # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension(Spatial) # Execute Aspect outAspect = Aspect(inRaster) # Save the output outAspect.save(F:\NW_Missouri_State_University\_Python_Class\Week_10\lab10\TestLab10_5) # Specify the current workspace as the workspace where the input elevation raster is. # Extract the base name of the elevation raster. arcpy.env.workspace = os.path.dirname(elevation) inputElev = os.path.basename(elevation) # Specify the output raster name as the input elevation name appending with “NorthFacing”. saveReclass = arcpy.env.workspace + os.sep + inputElev + NorthFacing # Check out the Spatial Analyst extension license for the script. arcpy.CheckOutExtension(Spatial) # Construct a map algebra expression to find the cell with elevation equal to the range values. minRaster = arcpy.sa.Raster(inputElev) = inRange_North1 maxRaster = arcpy.sa.Raster(inputElev) = inRange_North2 # Construct a map algebra expression to perform a Boolean And # operation on the cell values of minRaster and maxRaster. # If the cell value is 1 in both raster, then set the output cell value as 1. # Otherwise, set the output cell value as 0. Save the output raster as variable outRaster. outRaster = minRaster maxRaster # Create a remap object through RemapValue() function. # If the old value is 0, then set the new value as NODATA. # If the old value is 1, then set the new value as 1. remap = arcpy.sa.RemapValue([[0, NODATA], [1, 1]]) outReclassify = arcpy.sa.Reclassify( outRaster, Value, remap, NODATA) #Call the save method on the raster object to save the raster as permanent dataset. outReclassify.save(saveReclass) # Check in the Spatial Analyst extension license. arcpy.CheckInExtension(Spatial) I'm guessing that you've resolved this problem in the past week, but for future problems I encourage you to check what data types are expected for the functions you are calling. They can be unexpected sometimes in arcpy. Paul McCombs ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Exercise to work on
On Aug 12, 2014 3:29 PM, keith papa keith...@live.com wrote: Hi, am a newbie to python and I wondering if you guys can give me some exercise to work on. I have learned: print function , if function , strings, variables, and raw_input. The more the better Checkio.org is a game made of python coding challenges. They start simple, demonstrate functional testing, and provide other users' solutions. http://www.checkio.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with python script
Sorry, I missed copying this to the list. On Aug 4, 2014 8:13 AM, P McCombs mcco...@imperium.org wrote: On Jul 31, 2014 4:50 PM, McKinley, Brett D. bmckin...@mawss.com wrote: I would like to see if someone can help me with a python script. I’m trying to export a file geodatabase feature class to csv file. This is what I have so far: Does the code you attached execute successfully? Are you running this as a tool, or from the command line? Be cautioned that arcpy is outside the scope of this mailing list, but it won't have much to do with your questions at first. import arcpy import os import csv import domainvalues def export_to_csv(dataset, output, dialect): Output the data to a CSV file # create the output writer out_writer = csv.writer(open(output, 'wb'), dialect=dialect) # return the list of field names and field values header, rows = domainvalues.header_and_iterator(dataset) # write the field names and values to the csv file out_writer.writerow(map(domainvalues._encodeHeader, header)) for row in rows: out_writer.writerow(map(domainvalues._encode, row)) if __name__ == __main__: # Get parameters dataset_name = arcpy.GetParameterAsText(0) output_file = arcpy.GetParameterAsText(1) delim = arcpy.GetParameterAsText(2).lower() dialect = 'excel' if delim == 'comma': pass else: dialect = 'excel-tab' try: export_to_csv(dataset_name, output_file, dialect) except Exception as err: arcpy.AddError('Error: {0}'.format(err)) I would like for the script to export only certain fields and also export only the newest records. As for now, it’s exporting everything. It is best to try to add one new feature on your own and attach the result. You will get the best feedback that way. Thanks Brett McKinley ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How to create web interface?
On May 14, Danny Yoo wrote: Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P I have a little volunteer scheduling application I've written as a module, with about a dozen functions, that reads and writes to a Sqlite database. I'd like to run a web server on my machine just for my local use. I don't understand how precisely the web page would communicate with the python program. If anyone has a suggestion on specific modules, and tutorials to use to create a web interface for a python program, I'd love to hear it. I'm using python 2.7 on OSX Mavericks. I'm fairly new to python. I have some experience with apache, and php, I comfortable with HTML. I'm also happy to know where a better forum for this question would be. Thank you, Paul McCombs ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to create web interface?
Thank you all for your responses. This is exactly the information I was looking for. Paul McCombs On Tue, May 20, 2014 at 4:36 PM, Alan Gauld alan.ga...@btinternet.com wrote: On 20/05/14 21:00, P McCombs wrote: On May 14, Danny Yoo wrote: Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P I have a little volunteer scheduling application I've written as a module, with about a dozen functions, that reads and writes to a Sqlite database. I'd like to run a web server on my machine just for my local use. I don't understand how precisely the web page would communicate with the python program. If you want to understand the basics then the cgi module in the standard lib is a good starting point. It makes life a bit easier than nothing but exposes the underlying technology. But if you want something to keep you sane and make web programming easy then Pyhon has more web frameworks than you can shake a stick at. From very simple (Flask, CherryPy) to very complex (Django, Zope). There is a good page on the python.org web site that summarises the technology and many of the most popular frameworks but ultimately you just pick one and work through its tutorial. Start here for theory: https://docs.python.org/3/howto/webservers.html and go here for the list: https://wiki.python.org/moin/WebFrameworks HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor