Tag Info

New answers tagged

0

Condensed procedure outlined in http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/ for Windows 7, 32 Bits: 1) Install Python. I installed Python 2.7.9 from https://www.python.org/ 2) Install the GDAL binaries published by Tamas Szekeres. First, I launched IDLE (Python GUI) noting the following values: "MSC v.1500" and "on win32": In this ...


0

Here is one approach that performs the following actions: Create a new .mdb with old FGDB name, but in new workspace Find all FC's in FGDB--take into account empty FDS's Copy all FC's to .mdb import arcpy, os arcpy.env.workspace = r'C:\temp\inws' inws = arcpy.env.workspace outws = r'C:\temp\outws' fgdb = arcpy.ListWorkspaces(workspace_type = ...


0

A Raster Attribute Table (RAT) is the best way to associate string with pixel values. The formats with the best RAT support I know of are ERDAS Imagine (HFA) and KEA (KEA; http://kealib.org/). The steps I would use are: Write a raster with integer values (you can use GDAL to write a NumPy array). Add a RAT containing each pixel value (you can use the ...


0

You will need to use the ESRI tool structure and include the files in your script folder if you would like to reference them directly by name like you are doing in your code. http://resources.esri.com/help/9.3/ArcGISDesktop/com/Gp_ToolRef/sharing_tools_and_toolboxes/a_structure_for_sharing_tools.htm Otherwise, you will need to append the location of the ...


0

Another user asked a similar question on github, which might be of interest to you. Here's the gist of what one user recommended to import arcpy autocompletion data for anaconda: DamnWidget commented on Feb 26 https://github.com/DamnWidget/anaconda/issues/284 Open a PowerShell or CMD.exe and go to your anaconda installation under the Packages folder ...


-2

Use these commands: sudo apt-get install python-gdal sudo apt-get install gdal-bin


0

This works: caseList = [ ] def returnCase(inValue): global caseList if not inValue in caseList: caseList.append(inValue) return caseList.index(inValue) http://www.maprantala.com/category/esri/arcmap-esri/field-calculator/


1

Your best bet to get a weighted choice is to use numpy.random.choice which allows you to specify the sample set, and a weight for each sample. Note the probability must sum to exactly 1. raster = numpy.random.choice([0, 1], size=(rows, cols), p=[0.65, 0.35]) Also, a quick note: your comment says the probability that the landuse should be allocated to 1 or ...


2

The Esri help can be quite counter-intuitive, you need to know what you're searching for to get the description... The issue here is that the pictureElement doesn't have a geometry property.. see the Help page for picture element: However the IElement, which implements JpegPictureElement, does have a geometry: Explanation of Esri help symbols, they are ...


2

You can use the Python setdefault() method and an UpdateCursor to do this. import arcpy fc = r'C:\temp\your_shapefile.shp' # create an empty dictionary convert = {} # Start an update cursor and add unique ID based on unique string value with arcpy.da.UpdateCursor(fc, ["species", "code"]) as cursor: for row in cursor: row[1] = ...


1

This code snippet is C# and using an array called vertex to hold [x, y] double smRadius = 6378136.98; double smRange = smRadius * Math.PI * 2.0; double smLonToX = smRange / 360.0; double smRadiansOverDegrees = Math.PI / 180.0; ... // compute x-map-unit vertex[0] *= smLonToX; double y = vertex[1]; // compute y-map-unit if (y > 86.0) { vertex[1] = ...


2

Assuming that you always want to match like files from Original and Processed folders (i.e. Paris(O).shp always matched with Paris(P).shp or New York City(O).shp always matched with New York City(P).shp), You need to add a conditional after your second for loop to filter out everything you are grabbing from the processed folder. for f in glob.glob(root_dir ...


1

Are you looking for atan2 ? It's precisely meant to deal with this signs mess. https://docs.python.org/2/library/math.html#math.atan2


1

Ok, the first error is easy to avoid. It's failing because you are trying to find the datasource of a group layer, and group layers don't have data sources. Filter the group layers out by doing this: for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if not lyr.supports("DATASOURCE"): continue #further code here for non-group layers ...


3

Move your "is None" check up to the first evaluation. if Btype is None: return 'Olive' elif (Btype.startswith('Fig')): return 'Grape' elif(Btype.startswith('Lychee')): return 'Mango' Basically, if Btype is null, you can't do .startswith, etc. on it.


1

The result of json.loads(geojson) is a Python dictionary. You can simply use the json module (or the geojson module) and dictionaries as it was planned. geojson = "{'type': 'FeatureCollection', 'features': [{'geometry': {'type': 'Point', 'coordinates': [113.5546875, 63.704722429433225]}, 'type': 'Feature', 'properties': {'city': 'city1'}}, {'geometry': ...


0

it is not possible as qgis2leaf.qgis2leaf_exec works on a layer list from QGIS and the current map display settings.


0

Based on @nickves answer I adapted my code to the following which worked for me. import json city_name = "city2" city_geojson['features'] = [city for city in city_geojson['features'] if not city['properties']['city'] == city_name]


4

Could you do something like: Pre-Logic Script code: def mathFunction(y1, y2, x1, x2): return math.Atan(math.fabs(y2-y1) / math.fabs(x2-x1)) * (180/math.pi) Field = (on the bottom)...populate with your fields for y1,y2,x1,x2 mathFunction(!FIELDY1!, !FIELDY2!,!FIELDX1!,!FIELDX2!) See Python doc on the math module.


3

If you want to print the number of datasets that have been projected (not those that have just been copied), you should then create a 'count' variable and increment it each time you project a dataset. Be careful with the indentation of your code, the message must be added outside the loop (once, after all datasets have been reviewed). count = 0 #Loop ...


1

Just a quick hack that might suit you: import itertools t = {'type': 'FeatureCollection', 'features': [{'geometry': {'type': 'Point', 'coordinates': [113.5546875, 63.704722429433225]}, 'type': 'Feature', 'properties': {'city': 'city1'}}, {'geometry': {'type': 'Point', 'coordinates': [56.953125, 41.508577297439324]}, 'type': 'Feature', 'properties': ...


1

I solved it; arcpy.AddMessage(fc) arcpy.Project_management(fc, outFolder + "\\" + fc, template) not arcpy.Project_management(fc, outFolder + "\\" + fc, template) arcpy.AddMessage(fc)


2

Currently the best solution to read, work on and write csv files is the pandas module. Read a csv file (an example) import pandas as pd df = pd.read_csv("test.csv") print df type long lat o x y z t 0 AREA 44.37 -0.83 5 1 NaN NaN KKO 1 AREA NaN NaN 5 1 8 3 KKO 2 AREA 46.48 -0.85 NaN NaN NaN NaN KKO 3 AREA ...


1

I would put all your messages within the condition where the export is taking place. Otherwise, you will get messages of fc names that are not re-projected or error on the projCount value if the condition is false and the variable has not been created yet. for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name if fcspatialRef ...


0

It looks like you have a string with three variables that you are trying to send to the progress dialog of the Geoprocessing framework. I've made what I think are the variables show up bold below. 4 datasets have been reprojected to: WGS Web Mercator (auxiliary sphere) and saved in S:\GisData I suggest that you use a Python variable to count how many ...


3

Your indentation is incorrect. Your first code sample loops through all fcs, sets the fcspatialRef each time and does nothing else. It then exits the loop, compares the last fcspatialRef to spatialRef and projects or copies the last fc only, then calls arcpy.AddMessage(fc) only if the last fc is copied, not projected. Correct indentation: #Loop through ...


3

i may be way off, but i don't see where the issue is that the script does not actually copy the correct features - it simply doesn't print them to the dialogue as you would expect (?). As others have mentioned - this is difficult to assist as we can't tell if the issue is simply indentation problems. Here's what we could assume the indentation should be: ...


2

Since it looks like you are running this in a separate arcpy script (as opposed to inside the Field Calculator), there may not be a need to use Code Blocks. Maybe better to use an UpdateCursor... From what I can tell from the code, you are testing to see if the field you need to fill is either Null or 0, and if it is, fill the field with the value from the ...


4

There are 3 issues in your code: indentation under the for fc block as @recurvata says useless line after the else output not valid for the CopyFeatures tool. Here is the corrected code: #Loop through shapfiles in folder and reproject for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name if fcspatialRef != spatialRef: ...


3

It looks like you're kind of "over-checking" for matching spatial references, and you're if/else is a little off. Try this: # Get the spatial reference spatialRef = arcpy.Describe(template).spatialReference.name #Loop through shapfiles in folder and reproject for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name # the ...


1

As @user30184 says, gdal is just reading the values of your raster band, but you should be able to know the wavenlenght of each band based on the metadata (information you should get about the data). the two values returned by "ComputeBandStats()" will be the mean and standard deviation of the values in your bands. If the mean value is between zero and ...


1

See this example Create raster from array Replace the array with your own randomly created array. numpy.random as many random functions that you can use to construct the array as per your requirement


1

Try putting: sys.excepthook = sys.__excepthook__ at the start of your script


1

I got this error and unable to load "Processing" plugin. I visited many sites but didn't find satisfactory answer. The method worked for me is : Start QGIS. Error message will appear. Cut it and let qgis start. Go to Manage plugin Look at Red color Plugins or those need upgrading/downgrading Do the needful and it will work again


2

It looks like you already have the shapefile names being held in your fc variable so I suggest that the simplest thing will be to just use that. arcpy.AddMessage(fc)


0

In fact there are two (may be more) ways to do this- Using arcpy completely using arcpy and builtin library These are illustrated below Suppose I have three folder input, output and template Method One import arcpy arcpy.env.workspace = r"C:\Users\Winrock\Desktop\gstack\Project\input" fcs = arcpy.ListFeatureClasses() outputFolder = ...


1

You can use the name property of the Describe object: arcpy.AddMessage(arcpy.Describe(projectResult).name) >>> abc.shp Or you could aslo use the baseName property, to print the name without the .shp extension: arcpy.AddMessage(arcpy.Describe(projectResult).baseName) >>> abc


1

The problem is that with your first solution the result of roadsLayer.getFeatures() is an iterator and not a list ( iterable ) as in for feat in roadsLayer.getFeatures() and iterators can only be iterated over once, after which they are exhausted (look at Loop Like A Native, Understanding Python Iterables and Iterators or Build a Basic Python Iterator). ...


1

In your code: def EXPCODE(field_value): if field_value = "S4DNN2" return field_value "3.5" if field_value = "H2BNN2" return field_value "5.0" should probably be: def EXPCODE(field_value): if field_value == "S4DNN2": return 3.5 elif field_value == "H2BNN2": return 5.0 but if this is coming from the ...


1

This is easy to do assuming you mean that you want the Centroid coordinates of each parcel currently being calculated. Use !SHAPE.CENTROID.X! and !SHAPE.CENTROID.Y! as parameters to define the expression and then include them in the def as the east and north variables. If this is somehow trying to use two separate feature classes then you need to use a ...


1

Using the spatial reference name method will likely work for you. # Get the spatial reference spatialRef = arcpy.Describe(template).SpatialReference.name #Loop through shapfiles in folder and reproject for fc in fcList: fcspatialRef = arcpy.Describe(fc).SpatialReference.name if fcspatialRef != spatialRef: ...


1

Firstly, welcome to the site! Numpy arrays don't have a concept of coordinate systems inbuilt into the array. For a 2D raster they are indexed by column and row. Note I'm making the assumption that you're reading a raster format that is supported by GDAL. In Python the best way to import spatial raster data is with the rasterio package. The raw data ...


0

From a quick look at matplotlib, i'd say you have to alter the axis scales after the import.


2

They are inverted (width, height). Try this: . . . for row in range(height): for col in range(width): . . . Editing Note: I edited your code: from osgeo import gdal from PyQt4.QtCore import * from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry from qgis.core import QgsVectorLayer, QgsField, QgsMapLayerRegistry, QgsFeature, ...


2

I have met this problem before. Try to use """ instead of " above the expression. Otherwise, try this one : code_block = """def output(MTH_BRNT,YR_BRNT,YSLB): month = str(month_val) month_current = int(month)/n month_fire = int(MTH_BRNT) year = str(high_year)/n year_current = int(year) year_fire = int(YR_BRNT) Mc = (12*(year_current-1)) + ...


1

I've tested the following script on GNU/Linux, QGIS v.2.8.1, Processing v.2.6 and Processing v.2.9.1. import sys,os,glob from qgis.core import * from PyQt4.QtGui import * app = QApplication([]) QgsApplication.setPrefixPath("/usr", True) # Adjust it to your path QgsApplication.initQgis() path_dir = "/docs/borrar/test/" path_res = path_dir + "results/" ...


0

I came across this looking for something else, however I think your issue may be with the connect string and the DSN parameter, try adding Trusted_Connection=yes; after the DSN in the connection string. I usually run my arcpy scripts with their own database user and permissions without using Microsoft Authentication and the connection string looks like this ...


4

Am I correct in assuming you wish to carry out the operations in sequence i.e. the final value in the field comes from the !field![:9] operation? If so, i would have the code block as: def field_calc(field): str1 = field.replace("+","") str2 = "_".join([num.zfill(4) for num in str1.split('_')]) str3 = str2[:9] return str3 Then call it ...


0

In the code bloc : def calcField(field): f1 = field.replace("+","") f2 = '_'.join(num.zfill(4) for num in field.split('_')) f3 = field[:9] return f1+f2+f3 in the expression line: calcField(!field!)


2

If you specify a driver, OGR will only try to open your file with the specified driver. If you don't specify it, OGR will try to open your file with all the drivers. It will loop over all the drivers until it finds a driver with that it can open your file. The order it tries to open them is the same order as listed in ogrinfo --formats. See also this ...



Top 50 recent answers are included