Tag Info

New answers tagged

3

As the tool Sort_management creates an output table with the fields sorted this should be ok to do.. just remember that as a shapefile it wont stay sorted if you edit it; the edited row moves to the end of the table. From the description the tool expects a list of lists (or tuples I think), so to sort on multiple rows you need to create a list of lists.. in ...


1

In R: library(raster) library(animation) files <- list.files("path/to/asc", pattern = "asc$") saveHTML({ for (i in seq_along(files)) { r <- raster(files[i]) r <- plot(r) ## include additions like counties here } }) The animation package has other options for different output formats rather than HTML. The raster package has ...


2

potentially a multi-part question - 1) plotting grids with legends, 2) including shape files on grid, and 3) animate output images. each with multiple opportunities to accomplish the task. here's a quick run-down of at least 2-methods: using gdal, one should be able to read in the raster - perhaps something like (in a loop to get all rasters). raster = ...


1

To solve this bad behaviour of arcgis folder parameter processing, you need to string escaped the string that comes from the tool parameter. For this, simply add this line: dest_root = parameters[0].value #ouputs C:\Users\678910\Documents dest_root = unicode(dest_root).encode('unicode-escape') #outputs C:\\Users\\678910\\Documents And one problem with ...


0

I was able to get around this problem by using ReadRaster: from osgeo import gdal,ogr ds = gdal.Open( 'C:/Data/TestFiles/DtedFile.DT1' ) rb=ds.GetRasterBand(1) import struct xsize = rb.XSize ysize = rb.YSize datatype = rb.DataType #Reading the raster values values = rb.ReadRaster( 0, 0, xsize, ysize, xsize, ysize, datatype ) #Conversion between GDAL ...


1

You need to read the help file of the Mosaic to new raster tool. If you look at the Syntax section it lists the parameters of the tool and what they are. You need to be following the same order. Looking at your code you have a mysterious 1 after output name and before coordinate system. This is not the order of parameters as dictated in the syntax section. ...


0

This same error threw me off, too. Adding NODATA transparency value parameter to the call fixed it for me, so instead of dal2tiles.py -z 1-10 ~/hfp_wgs/hdr.adf hpf-tiles I called dal2tiles.py -z 1-10 -a 0,0,0 ~/hfp_wgs/hdr.adf hpf-tiles and it started working. Note that the value had to be three numbers, one for each of RGB channels.


1

The code presented in your question doesn't match what is asked for in the question. "I'm trying to label certain features using a specific field (osm_name_58_en). However, when this field is null, I want to label the feature with (som_english_32_name). If both are null then I want to label with the (amenity) field." This sentence implies that you only ...


2

The Correct form of your code is : def FindLabel ( [amenity], [osm_english_32_name], [osm_name_58_en] ): if not ([osm_name_58_en] is None): return [osm_name_58_en] elif not([osm_english_32_name] is None): return [osm_english_32_name] + '\n' + [amenity] else: return [amenity] The semicolon in the last line is removed. ...


0

Yes, it can be done. You will need urllib / urllib2 to download the csv. (See this stackoverflow question.) To load the CSV you will probably want to use Make XY Event Layer To transform coordinates you will need to Project it.


4

To resolve the issue I did the following: Deleted extra installs/instances of Python outside of my ArcGIS10.3 folder. Reset my environment by following the steps in "Learn Python The Hard Way" by telling it to look in "Python27\ArcGIS10.3" Used "Repair Program" from the Setup application within the main folder for ArcGIS\Desktop Things seem to be ...


0

While I cannot comment on the suggested implementation, you may want to check an existing implementation of histogram matching done for GRASS GIS 7 (here an addon): https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.histo.match For the manual and an example, see http://grass.osgeo.org/grass70/manuals/addons/i.histo.match.html The code is ...


1

write 'D:\ne_10m_airports' as 'D:/ne_10m_airports' (change with uri formalism) or 'D:\ne_10m_airports' (escaping) or r'D:\ne_10m_airports' (r means raw string) regards


3

For brevity's sake: def FindLabel ([field]): val = [field] return ''.join([j for i, j in enumerate(val) if j != '0' or i == 1]) Step through the string and toss away all 0's unless it's in the middle position (index of 1), then join what's left.


2

Just for good measure, here's a way to use python string methods. This would work with strings of variable length, though I know that wasn't a consideration in this case: def FindLabel(value): if value.endswith("0"): value = value[:-1] # slice all but the last character if it's a 0 return value.lstrip("0") # take off any leading zeros


3

Here's a little more concise way of doing it. Basically convert it to a list and replace list[0] and list[2] with '' if the value is 0 def FindLabel([field]): value = [field] l_value = [x for x in value] # turns string to list no_zero_positions = [0,2] # where you don't want zeros for p in no_zero_positions: if l_value[p] ...


5

Use Python as the parser, and check the Advanced box. Then just replace yourFieldName with the name of the field you want to label. def FindLabel([yourFieldName]): value = [yourFieldName] first = False third = False if value[0] == "0": first = True if value[2] == "0": third = True if first == True and third == ...


1

The tool "Symmetrical Difference" can also do this: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000000r000000 This tool is available in QGIS, a free GIS you can download here: http://www.qgis.org/en/site/forusers/download.html


1

The exact tool you are looking for is called "Erase". Unfortunately, it is only included in the Advanced/ArcInfo license level. You might be out of luck unless you can write your own version of this tool. ArcGIS Erase


1

I just experienced the same problem. It looks like ArcGIS is caching the tools/scripts. If I refresh (F5) the toolbox, after a few seconds the toolsets and tools would show-up and work, but next time I open ArcCatalog it shows the red crosses again. If you rename the folder where the PYT is stored, it won't show the red crosses the first time, only after ...


5

This is definitely possible. I just did a test, and I was able to get it to work by using float() around the Acres variable. So, this worked fine for me: def FindLabel([PARCEL_NUM], [PROP_ADDRE], [Acres]): if float([Acres]) >= 10.0: return [PARCEL_NUM][-8:] + '\n' + [PROP_ADDRE] else: return [PARCEL_NUM][-8:]


1

Took me a few tries and some digging to realize but, as per the ArcGIS Help: Note: To label a subset of features based on a field value, create the SQL query in the label class instead of through the label expression. So try creating a label class for those features greater than or equal to 10 acres(SQL) then use the expression to format the label. ...


0

The following requires a Spatial Analyst license. The ArcPy Raster Object provides a pretty intuitive interface to working with rasters. Once a Raster Object is created, you're allowed to perform math operations on it in a very similar manner to operations on python built-in objects. Properties and methods onboard the Raster Object should also be useful for ...


1

Change variables indir and outdir according to your need. The code will find each file with extension 'txt' in indir and every subdirectory of indir. If you need another coordinate system than EPSG 4326, please change the EPSG number in line 9. The converted files will be written to directory outdir. import os indir = 'G:/LANUV' outdir = 'G:/LANUV' for ...


0

Thank you for opinion, I'll keep it in mind. I've solved the problem by installing ArcGIS 10.3.1 (from ESRI website, not from prerelease as before).


0

I had same problem yesterday. Step 1: Build a GUI creator something like (ui2py) to make a py file out of your ui. import os os.system("C:/Python27/Lib/site-packages/PyQt4/pyuic4.bat -x testing_module_dialog_base.ui -o testing_module_dialog_base.py") print("Done!") Step 2: Your plugin_module_dialog.py will look like that.. import os from PyQt4.Core ...


0

From what i understad, you want to clip / select all features depending on a date? If this is the case you can use the python module : shapely or ogr2ogr. You can have a look at this link : code examples, ...


0

I have a script for this task. It was developed for processing Landsat data. Usage: DATE(161, 2015) Prints string: '2015.06.10' Here is a code (sorry, but comments and some messages are in russian): # -*- coding: cp1251 -*- # функция определения даты по году (ХХХХ) и дню (ХХХ) в формате: от 1 до 365(366) def DATE(DAY, YEAR): DAY = int(DAY) YEAR ...


5

Yesterday I had no time to create it in details... See my solution in 4 steps: CREATE OR REPLACE VIEW bd_segment AS SELECT ST_PointN(geom, generate_series(1, ST_NPoints(geom)-1)) AS sp, ST_PointN(geom, generate_series(2, ST_NPoints(geom) )) AS ep FROM -- extract the individual linestrings (SELECT ...


2

You can't really change the symbology of a layer in arcpy with the level of customization you have when just right clicking a layer and using the symbology menu. However, you can make a "template" layer that contains the symbology you want and then use ApplySymbologyFromLayer_management (in_layer, in_symbology_layer). This will allow you to apply the ...


3

It is not possible to change the properties of a layer directly. The properties of a layer can be changed, but only by importing properties from another layer in the map or a layer file. Even the layer name cannot be changed without an existing layer or layer file. "UpdateLayer" in the ArcGIS Help can give you more details and some examples.


0

You are probably trying to output Unicode characters into the terminal which does not know them. I'd suggest writing the results to a file instead, so that you can do something like this: import arcpy,os,fnmatch,unicodedata,codecs rootPath = r"C:\Project\layers" pattern = 'mig*.shp' with open('results.log', 'w') as logfile: for root, dirs, files ...


0

You must enclose your table name in double quotes for PostgreSQL to recognize capital letters. --> "Seg_060_2009"


2

You have to change several things in the csv file and the code. In the first line of your csv file add the column labels x and y, since they are missing. The other labels are fine. par;num;ano;mes;dia;D;btq;x;y Since your decimal separator isn't the default colon but a comma you have to specify this explicitly. The fully qualified file name hasn't the ...


2

Edit based on the comments below: Assigning the gdal_array.SaveArray(a, "test.tif") call to a variable returns an osgeo.gdal.Dataset object that can be managed as a per the below gotchas. Using the above example this should work: a = np.arange(300).reshape((3, 10, 10)) ds = gdal_array.SaveArray(a, "test.tif") ds = None ...


2

One thing to remember, all actions that involve the parameter should be off the parameter object; so use parameters[n].setErrorMessage(msg) instead of arcpy.AddError(msg). AddError is used to add error messages into the tool execution messages, setErrorMessage is to add an error to the parameter that will block the tool from executing. So you also don't need ...


1

Using an Update Cursor in a Python script is an efficient approach. The following example takes the last word in the Owner_1 string and the first word in the owner string and compares the values. import arcpy fc = r'C:\path\to\your\database.gdb\feature_class' with arcpy.da.UpdateCursor(fc, ["Owner_1", "owner", "NAME_CHK"]) as cursor: for row in ...


2

Using a Python parser, calculation would look like: This will return a 0 for your first two records, and a 1 for the last three. Edit: for @Masonerman9's comment about good enough matches. Could try difflib. I haven't used it much, but it does build in some tolerances for string comparisons. The below will give you a 1 only for the fourth record (Randy ...


2

It looks like you need to pull out the name of the file from "inRaster" and add it into your "outname" variable. I've copied your last block of code and added comments to the lines I've added/edited. If the rest of your code is working as you indicate, this should take care of fixing the name and writing it where you want it. inRaster = ...


1

Probably is related... but you are mixing QgsVectorLayer commit with QgsVectorDataProvider methods. You have to avoid mixing because they work on different workflows! using dataprovider you write directly on the file using dataprovider interface... and you write it every updateFeature (well could be managed a cache depending on provider... but it's leaved ...


2

You could try using geoalchemy2. Personally I would look at using the Object Relational Mapper (ORM) model for working with your data, for example: from sqlalchemy import create_engine # Enter your database connection below engine = create_engine('postgresql://gis:gis@localhost/gis', echo=True) from sqlalchemy.ext.declarative import declarative_base from ...


0

I don't have direct experience with this but I found these situations that may help bring you to a solution: http://stackoverflow.com/questions/8949252/python-attribute-error-nonetype-object-has-no-attribute-something http://stackoverflow.com/questions/26557074/attributeerror-nonetype-object-has-no-attribute-get


1

As commented by @Luke, and as we were both working towards: If that is your actual code, your for lyr in arcpy.mapping.ListLayers(mxd): loop will only run on the final mxd as it is not indented to be inside the for file in mxdList: loop. Instead of your code try: import arcpy, os #workspace to search for MXDs Workspace = ...


2

I asked too quick. According to this thread, the 1411380301000 value is: ...presented as epoch milliseconds since 01/01/1970 GMT. And I used the following code to convert it: import time value = 1411380301000 date = time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(value/1000.0)) print date >>> 09/22/2014 10:05:01


6

There is a large amount of documentation from ESRI on creating your own tools in Python, so I will assume that you can access your selected layer without issue. There are many methods for selecting data randomly, for example choosing in random number in the range of the number of features (using the random module as suggested by @MichaelMiles-Stimson above), ...


0

Your code is not going to work for these reasons: You need to add a wildcard "*" to ".mxd" and ".lyr" so that these return something (lines 3 and 4) You referenced "mxds" instead of "maps" on line 6, and it needs to be referenced as a arcpy.mapping.MapDocument because you need to save later. You need to nest the add each layer in a loop (line 8) You ...


1

When saving the raster, you're using outputDir which is a folder, not a valid raster path. Also keep in mind too that your input folder and output folder are the same, so you're also setting up a situation where you'll be overwriting your inputs with your outputs. For the save, could do something like this: outRasterName = '{}{}'.format(outputPrefix, ...


1

As Luigi anwered: self.canvas.scene().addItem(...) adds image to the canvas. Thanks!


1

a QgsMapCanvas is a QGraphicsView so you can add graphics items as usual in the scene of this class QGraphicsScene regards


0

Your approach is very interesting. The Editor class in PyShp is still a work in progress but I'll look into it further. Here's some code I just tested using your bounding box on a US roads shapefile. PyShp does export the SHX and the DBF files. Those are the minimum requirements of a shapefile. The SHP file is the geometry, the SHX file is a simple ...



Top 50 recent answers are included