Tag Info

Hot answers tagged

6

My method for this was to use the Field Mappings and Table to Table conversion functions. Using field mappings you can set new fields based on the names of fields in your input table. The following link has examples for feature classes: http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000007p000000 My code below will change all fields in an ...


4

As @minus34 said above, you almost certainly have latitude and longitude, rather than eastings and northings, so your projection is likely to be WGS84 (or because you're in Australia, GDA94). To do the transformation in pyproj (assuming GDA 94) you can use: import pyproj latitude, longitude = -33.75, 150.0 gda94 = pyproj.Proj(init='epsg:4283') mgaz56 = ...


3

In Python a backslash is an escape character. In order to put a backslash in the string you need to need to put another backslash next to it to stop it from forcing a new line. myString = "this is\\ a string with a backslash" I can see your paths are set correctly but maybe the strings you are parsing only have a single backslash. You can solve this ...


3

The Python csv module can handle these edge cases. The module also supports all different kinds of delimiters, not just commas. Assuming that this is our input data where the third element has a literal comma in the string: OutputRow = ["one", "two", "three, four"] Using the basic text writer, the output row is incorrectly interpreted as four columns: ...


3

I would usually suggest the da.SearchCursor as well, but its order by clause only works withe data in a database. So, if it is in a database: a_table = "YourTable" order_fld = "Time" return_flds = ["Time", "SomeOtherField"] where_str = """Time > DATEADD(minute, -2, GETDATE())""" sql_clause = (None,'ORDER BY {} DESC'.format(order_fld)) last_row = '' ...


3

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor: import arcpy # The input FC fc = "C:/W/Sik.gdb/yourFC" with arcpy.da.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor: for row in ...


3

Your function is not returning anything. I've modified your code to return the value of aspect_m60. # Calculate Field import arcpy # Set environment settings arcpy.env.workspace = "c:/W/Sik" # Set local variables inTable = "Point" fieldName = "aspect_m60" expression = "getCalc(!aspect!)" codeblock = """def getCalc(aspect): if (aspect < 60): ...


3

Try the following: if os.path.basename(o).split(' ')[0] == os.path.basename(p).split(' ')[0]: print p This splits the basename where spaces (' ') occur, creating a list of string parts, and returns the item in the list at index 0 (the first item). You would need to modify this to split at any other character (i.e. underscore, hyphen, etc)


3

Here is a block of code to get you started. This should change dependent on whether you are performing an append or merge. You will also have to create separate lists and loops/appends for your line data and point data. # import modules to use import arcpy, os # input folder containing your new shapefiles inputFolder = arcpy.GetParameterAsText(0) # ...


2

You need to filter away those map documents which contain "land use" in their names. It is better to test and if the evaluation gave us "false", proceed with the processing. env.workspace = r"C:\Project" Layer1 = arcpy.mapping.Layer("abc.lyr") for mxd in arcpy.ListFiles("*.mxd"): if 'land use' not in mxd: print mxd mapdoc = ...


2

Having looked at your code where is row[] being created, I guess we are not seeing the full picture? I've seen this "GPL0" error before. It's indicating that the first parameter is invalid. If you look at the syntax section of the help for this tool it states the input features are of Data Type FeatureLayer. As we are not seeing the full code we have no ...


2

Okay, got it meanwhile. There are probably different ways to do this but this one works fine. Apart from access to your Spatialite database via Python's sqlite3 module and the Spatialite extension, you'll need the geojson module (simply installable with pip). Connect to your database as usual: import sqlite3 import geojson # open a Spatialite database ...


2

This is a great example of how relatively simple arcpy.mapping scripts can offer more functionality than Data Driven Pages. First, if you haven't already, run a Spatial Join with your trees as your target layer and your districts as your point layer using the INTERSECT match option. It's better practice to perform a spatial join and apply a definition query ...


2

You are trying to set the field within the code block, when actually you need the code block to return the value you're looking for. If you just just add return aspect_m60 after the else block, it should work fine. Think of the code block as a place to write functions whose results can be used in your field calculator expression.


2

Another idea, though all these answers should work. This will avoid having to iterate the whole cursor. Not sure if the sql_clause will decrease performance though: oid_field = "OBJECTID" sql = ("ORDER BY {0} D".format(oid_field),"") with arcpy.da.SearchCursor(table,"*",sql_clause=sql) as cursor: for row in cursor: last_row = row break ...


2

You can do this with a Search Cursor wrapped in a list comprehension: import arcpy # Your input shp of fc fc = r'C:\path\to\your.shp' # List all of the row values as a list of tuples rows = [row for row in arcpy.da.SearchCursor(fc, "*")] # Get the last row print rows[-1]


2

If you're using 10.2, I would first recommend using the data analysis version of the search cursor. Then you can use python's list comprehension to get the last value. Try something like the code below. It creates a list of all values in the 'time' field, and then accesses the last record through indexing (the [-1] at the end of the list comprehension ...


2

Max, I'm the author of PyShp. What you are trying to do is very standard GIS stuff. Download QGIS. It is basically the open-source ArcGIS. It bundles all of the best of breed open source GIS tools into a nice GUI as well as a fantastic Python automation framework. There are dozens of free tutorials and videos for performing different tasks. There also lots ...


2

Shapefiles don't support nulls. Read the section 'Null value representation' here: http://desktop.arcgis.com/en/desktop/latest/manage-data/shapefiles/geoprocessing-considerations-for-shapefile-output.htm If you really need to have nulls, consider migrating this data into a geodatabase.


2

Use else: row[1] = None None is what Python uses for Null. I'm not very familiar with regex, so I'm going to suggest a different version of your cursor operations, see if this works: for row in cursor: if row[0] == " ": row[1] = None else: row[1] = round(float(row[0]), 1) cursor.updateRow(row) The issue may ...


1

perhaps a couple of resources on this - here's another stack question that may be a duplicate. or portions of this page might be helpful - in any case, it appears to be a two step process - first create the .dbf from the csv then create the spatial information from a vrt file (small xml-like file with basic information about your data and output ...


1

At this point I haven't implemented this stuff myself, but the approach that I am planning on is combining boto with the information on Amazon's page on Landsat on AWS. At first glance, it appears to be a rather doable task. Another option is landsat-util which can be found on github, which is python-based and can interface with AWS.


1

OK so I wanted to convert islands to holes and holes into islands but couldn't find a command to do it in QGIS so I wrote a script myself. Here is that "simple" script which will invert an input_layer into a bbox polygon in an output_layer. The whole process ran over a couple of seconds to invert a 25MB shape file. Better than crashing out with a call to ...


1

Thanks to GeospatialPython.com who pointed me in the right direction, I was able to throw together a quick Python script to do this. I'm sure there are issues here because I'm not very familiar with pyqgis, but it does appear to work (here is how to verify it through the QGIS GUI. from qgis.core import * # Note: add ...


1

To be honest I'm not sure that this will work but have you tried smoothing/simplifying the shapefile? This can be done in QGIS (alternatively try http://mapshaper.org/). I would try it myself but I don't have any shapefile data similar to what you've described. Regards, Eamon


1

I would simplify things a bit and convert your string to float using float(). I used the new cursor style, which you may prefer. Please test this "untested" script on a sample dataset before going live. import arcpy, os from arcpy import env arcpy.env.overwriteOutput = True env.workspace = "C:\Users\OuelletteMS\Desktop\Ice_Data_testarea" listFCs = ...


1

You are using Decimal against the field name, not the value. Try row.setValue(newNCT, Decimal(row.getValue(strNCT)))


1

Your code is uncomplete and not well formated. However, this adaptation seems to work as it is espected: canvas1 = iface.mapCanvas() layers = [] n = canvas1.layerCount() for i in range(n): layers.append(canvas1.layer(i)) canvas2 = canvas1 properties = {"color": "255,0,0", "outline_color": "255,0,255"} symbol = ...


1

the most easy way to do this in a script is to use the subprocess module and gdal_translate import subprocess image_in = "path_input_image" image_out = "path_output_image.tif" subprocess.call(["gdal_translate.exe","-co", "TILED=YES", "-co", "COMPRESS=LZW" "-ot", "Byte", "-scale", image_in, image_out ] if you are in Linux, you don't need the ".exe" after ...


1

You can do that directly in QGIS with Raster -> Conversion -> Translate (Convert Format). To test it, I used a Float64 (Sixty four bit floating point) raster (named test) loaded in the Map View of QGIS. To convert it to Byte (8 bit type), I named it first at the "output file space" as test_byte.tif and afterward, I click in the icon pencil of "Translate ...



Only top voted, non community-wiki answers of a minimum length are eligible