Tag Info

Hot answers tagged

7

This sort of question is better answered in StackOverflow but the answer is straight-forward enough so I'll give you a hint here. Your date is not a date as far as Python is concerned but a division sum - which is the main reason why it doesn't work. Your code also won't give you the last four digits. You need '[-4:]' (yours gives everything except the ...


7

In cursors, length is a read-only property. I couldn't imagine what a predictable outcome would be for setting a new length of a line. Would it just extend the last point out in the bearing from the next to last point? What if it were multipart? Would it grow the entire polyline segment by segment?


6

See the OGR Projections tutorial and the OGRSpatialReference class. In particular, the GetAttrValue method. Here's a worked example. from osgeo import gdal,osr ds=gdal.Open(r'SOMERASTER.TIF') prj=ds.GetProjection() print prj srs=osr.SpatialReference(wkt=prj) if srs.IsProjected: print srs.GetAttrValue('projcs') print srs.GetAttrValue('geogcs') For my ...


6

>>>'R12345678910'[1:] '12345678910' Edit Appending [1:] to a string in python will remove the initial character. Look up slice in the python help. To use this in the ArcGIS field calculator, you will need to turn on Python parsing for the unitCode = enter !your_field_name![1:]


6

It looks like you are missing another zone = cursor.next() within the While loop You need to increment the cursor to the next feature after you're done with it or the loop starts over on the same feature. incidents = r"c:\users\documents\arcgis\arcgis tutorials\psu tutorials\project3\policedata.gdb\GraffitiIncidents" patrol_zones = ...


6

As already been mentioned in GS exchange, the QGIS version of Kyng Chaos uses the standard Apple Python and the version 2.x (and not the 3.x, nor others Python implementation, Homebrew, Anaconda, etc.) As indicated in the documentation, you must first add PyQGIS to the PYTHONPATH I use here the Terminal application: export ...


5

If you add a geoprocessing tool to a toolbar it will run immediately upon clicking it, provided it has no parameters:


5

You can actually deal with each part of a multipart polygon by creating a separate polygon object. Take a look at the following code. import arcpy from arcpy import env env.workspace = "C:/Data/Exercise08" fc = "Hawaii.shp" for row in arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"]): print("Feature {0}: ".format(row[0])) partnum = 0 for part in ...


5

getClass (In , Out , Therid, freq ) if FREQUENCY== 1: return str(In) elif FREQUENCY== 2: return (str(In) + "-" + str(Out) ) elif FREQUENCY == 3: return (str(In) +"-" + str(Out) + "-" + str(Therid) ) else: return "other frequency" here is a quick fix. Concantenation in Python uses "+", and I converted ...


4

Did you check this page? It may give you some idea how to set it up: http://grasswiki.osgeo.org/wiki/GRASS_and_Python -> Creating Python scripts that call GRASS functionality from outside --> MS-Windows


4

VBScript Example: Right( [FieldName], 11 ) This code will take the 11 characters from the right, and anything left of those 11 characters is omitted. Python Example: !FieldName!.lstrip('R') This code takes a string and removes R from the left/front of it. Both of these examples should get rid of the R in your strings. Edit: Regan Sarwas' updated ...


4

The syntax is Dissolve_management (in_features, out_feature_class, {dissolve_field}, {statistics_fields}, {multi_part}, {unsplit_lines}) You need to specify the dissolve_field as the third parameter - here you've left it blank.


4

Under the hood QGIS uses GDAL/OGR for most of the functions. So, the Python API for GDAL would be the closest analogy to using ArcPY in a stand-alone situation. You can use the installation that comes with QGIS or have a separate installation of Python and GDAL. Other addons that complete the 'package' I would include Shapely Numpy SciPy The last ...


4

If an unhandled exception, such as an ImportError, occurs before the add-in classes are instantiated they will become unresponsive, be given a [Missing] label, and have a red symbol for their icon in the case of items on toolbars or in menus: You can confirm whether an import error is happening by wrapping your import statement with an exception handler ...


3

There are a couple of ways to do this. The quickest would be to read the file as you have done and then use the string split function. b = open("test.txt", "r").readlines() line = b[-2].split() #Gets the second last value from the list and split on whitespace return float(line[-1]) However this isn't very reusable. If you're doing this for lots of similar ...


3

I think it's because GDAL wasn't able to create a layer from the shape file. The offending line: out_shp = '%s\test_OGR.shp' % (path,) You have to escape the slash, like so: out_shp = '%s\ \test_OGR.shp' % (path,) Otherwise, Python would will treat the \test part as \t or tab. Your resulting path would then be: D:_tempAuto est_OGR.shp ...


3

OGR is unable to open your dataset. Check that the dataset exists, the path is correct and that you have a version of GDAL/OGR with GRASS vector support as it is not compiled by default. To check if you have GRASS vector support, type ogrinfo --formats at a command prompt.


3

You're doing your installation wrong. Instead of pip install shapely use the Windows installer available at https://pypi.python.org/pypi/Shapely#downloads And click on the file Shapely-1.2.17.win-amd64-py2.7.exe Launch the install and it will be OK after. Just as an information, "pip install shapely" works when you have the C compiler installed to ...


3

This looks like a simple logic error. I'm assuming that you want the first feature in the cursor to be updated with the first item in the list, then the second feature with the second item, etc. As written, you're updating the same row over and over again with each element of the list. (Then repeating the process for each row.) Maybe your loop should ...


3

You could do this by analyzing the point's position relative to the centroid of the polygon. If would just be a matter of calculating the angle between the two points and then testing that angle to determine which quadrant it runs towards/into. So for example, if the angle between two points is 45°, then it's running towards the northeast corner, if it's ...


3

Please see this earlier answer: How do I include a variable in the where clause of arcpy.Select_analysis? However, to point out the specific issue here, you are trying to format the string using an unsupported syntax. The line "\"NAME\" = '%Select_County%' " will simply result in the string "NAME" = '%Select_County%'. No string interpolation has been ...


3

This code would work for you. import arcpy arcpy.env.workspace = r"C:\GIS\93_data\93" workspaces = arcpy.ListWorkspaces("*", "FileGDB") for workspace in workspaces: desc = arcpy.Describe(workspace) if desc.release != '3,0,0': arcpy.UpgradeGDB_management(workspace, "PREREQUISITE_CHECK", "UPGRADE")


3

First make sure you have the 32 bit PyScripter installed, not the 64 bit. Then in Tools -> Python Path make sure you have PyScripter pointing to the following paths: C:\Program Files (x86)\PyScripter\Lib\rpyc.zip C:\Windows\system32\python27.zip C:\Python27\ArcGIS10.2\DLLs C:\Python27\ArcGIS10.2\lib C:\Python27\ArcGIS10.2\lib\plat-win ...


3

Ok, so this answer works for the Anaconda 64bit Python distribution with ArcGIS 10.1 64bit on Windows 7/Windows Server First, install anaconda, it should go to the directory C:\Anaconda. Check the box 'make system default python'. It may give a warning that there is another python installed, but continue. Then: First thing to do is to copy over the ...


3

Python code must be indented correctly to be valid. For example, taking a wild guess at the intent of your code, it might be something like: import urllib2 import simplejson as json data = urllib2.urlopen( "http://api.openweathermap.org/data/2.1/find/station?lat=%s&lon=%s&cnt=1"% (lat, lon)) js_data = json.load(data) if js_data['cod'] == '200': ...


3

Documentation of r.watershed module for GRASS 6 says that there is a half.basin option (parameter): half.basin Output map: each half-basin is given a unique value So, this means that in command line (Bash etc.) one can write: r.watershed elevation=elev_lid792_1m drainage=elev_lid_drainage half.basin=elev_lid_half_basin threshold=10 GRASS provides a ...


3

First, never swallow an exception, or catch all exceptions. Your connection code should be more like: import sys import psycopg2 conn = None try: conn = psycopg2.connect("dbname = 'routing_template' user = 'postgres' host = 'localhost' password = '****'") except psycopg2.DatabaseError, ex: print 'I am unable to connect the database: " + ex ...


3

You can set the value of the parameter to the values you want to be checked, at least when using a Python Toolbox. The same should be true for your case. For example: def getParameterInfo(self): p = arcpy.Parameter() p.datatype = 'String' p.multiValue = True p.name = 'test' p.displayName = 'Test' p.parameterType = 'Required' ...


2

When configuring python for grass I faced with same issue. I've found grassrc6 under APPDATA: It doesn't matter what the file is called, so long as %GISRC% points to it and it contains the necessary settings. The normal location for GRASS 6.x on Windows is: %APPDATA%\GRASS6\grassrc6 On Windows 7, a typical setting for %APPDATA% is ...


2

Here is code snippet for people who would like to use it: import arcpy import pythonaddins class DrawRectangle(object): """Implementation for rectangle_addin.tool (Tool)""" def __init__(self): self.enabled = True self.cursor = 1 self.shape = 'Rectangle' def onRectangle(self, rectangle_geometry): extent = ...



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