POST
|
Yes that will definitely work too. There is an environment setting XYTolerance which defines the distance before points 'snap together' that might make it easier as well.
... View more
11-10-2016
01:20 PM
|
1
|
0
|
1273
|
POST
|
The 'object.touches()' predicate is useful for that, a polygon can have a minimum of three edges. So you can use touches to check if the third line and beyond touches both the first line and the prior line. If so that line closes the polygon.
... View more
11-10-2016
12:36 PM
|
0
|
2
|
1273
|
POST
|
In the JSON the 'geometry' key's value is not consistent. Some of them are points (why you're getting the key error), so you'll want to handle it conditionally. Also many of the geometries are only a line between 2 points, you would need to group the lines that form a closed polygon into a collection, then pass all of their points to the polygon constructor.
... View more
11-10-2016
12:12 PM
|
1
|
4
|
1273
|
POST
|
Yes typically I would recommend getting used to PEP8 style, it is used for the majority of Python projects and is something that is appreciated during coding interviews ArcPy actually breaks PEP8 in a lot of places for a number of historical reasons, so its not the best reference for the canonical Python style. Edit: Late to the party. Oh well.
... View more
11-10-2016
11:19 AM
|
0
|
0
|
1082
|
POST
|
edit: I have 10.5 installed, please change the paths below to the correct version that you are using Yes it is possible. PythonWin uses a windows installer which checks your registry and installs the package in your specified Python2.7 location - Currently it seems yours is at 'C:\Python27\python.exe' and it should be 'C:\Python27\ArcGIS10.5\python.exe' instead. First, uninstall PythonWin because its using the wrong registry value, we will reinstall it in a minute. Then save this script as 'C:\Python27\ArcGIS10.5\reg.py': #
# script to register Python 2.0 or later for use with
# Python extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html//www.mail-archive.com/distutils-sig@python.org/msg10512.html//www.mail-archive.com/distutils-sig@python.org/msg10512.html//www.mail-archive.com/distutils-sig@python.org/msg10512.html
import sys
from _winreg import *
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)
def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"
if __name__ == "__main__":
RegisterPy() Then from a cmd prompt run: C:\> C:\Python27\ArcGIS10.5\python.exe reg.py You should see a message '---Python 2.7 is now registered!' To verify its the right version, from the cmd prompt run 'C:> python' Then within the interpreter run import sys
print sys.executable and it should return 'C:\\Python27\\ArcGIS10.5\\python.exe' If this is the path, you should now be able to reinstall PythonWin and verify in the install wizard that it is now pointing to 'C:\\Python27\\ArcGIS10.5\\python.exe' then you should be good to go!
... View more
11-10-2016
11:09 AM
|
1
|
2
|
1812
|
POST
|
As for autocompletion, there's a large number of Python IDEs which may suit what you're looking for. Personally I use PyCharm for larger programs and Spyder for data science scripting.
... View more
11-10-2016
10:11 AM
|
1
|
0
|
329
|
POST
|
Hi Ravi, Based on the File "C:\Python27\Lib..." in your stack trace it looks like you're using a version of Python that you installed rather than the one that is included with ArcGIS. There can be multiple instances of python.exe on one machine - since arcpy depends on some of our DLLs it only works with the ArcGIS copy. Try looking for a python.exe in "C:\Python27\ArcGIS10.4" (or whichever 10.x version number you're working with) and run your script using it instead.
... View more
11-10-2016
10:07 AM
|
1
|
4
|
1812
|
POST
|
Hello Eric, If I understand you correctly you'll want to look at DataFrame Objects and its extent property (in 10.x) or Camera Objects (in Pro) which uses the getExtent() - Both of these should return an Extent Object from which you can get the XMin, Ymin, Xmax & Ymax properties from to figure out the center point.
... View more
11-10-2016
10:00 AM
|
1
|
0
|
957
|
POST
|
Hi Dan, I agree. I had to do a bit of digging to figure that out so I don't think its common knowledge but I'll definitely recommend that we mention it in the docs.
... View more
10-21-2016
03:29 PM
|
2
|
0
|
1077
|
POST
|
Hi Chris, The cast is necessary because the field's value is returned as an object (that is, the Python base class), since arbitrary data types are supported by the expression dialog. String.format() does not work with uncast objects because an object.__repr__ method returns a 'method-wrapper' class and not a datatype that string.format knows how to work with. Once you've cast the object, in this case invoking its __float__ method, it returns its value as a float data type which plays nice with string formatting.
... View more
10-21-2016
03:09 PM
|
1
|
2
|
1077
|
POST
|
Just a small nit to pick, but the actual question being asked isn't answered by his response and could be misleading to novice programmers. It asks how to count rows being processed with an insert cursor, not how to count the number of rows in a text file. These may not be equivalent if the rows are inserted conditionally.
... View more
10-12-2016
09:58 AM
|
1
|
0
|
1160
|
POST
|
Since you are ultimately using an insert cursor, it may be simpler to have several functions: One function to read the lines out of the text file into a list and another function to loop through that list to insert to the feature class. Then as an intermediate step you can use Python's len() keyword to easily get the length of the list.
... View more
10-11-2016
02:43 PM
|
1
|
0
|
1160
|
POST
|
As far as using Arcpy on a mobile device, no its not possible as it depends on the .dlls installed by Desktop or Server to work. You may be able to achieve what you want however by adding metadata fields and deriving the symbology from those https://doc.arcgis.com/en/collector/ios/create-maps/gps-map-prep.htm
... View more
10-11-2016
02:19 PM
|
0
|
0
|
295
|
POST
|
Two quick ways off the top of my head: First, if the AssetID field isn't yet populated you could use a cursor to fill it in: prefix = 'SN' with arcpy.da.UpdateCursor(file, ['AssetId']) as cursor: for i, row in enumerate(cursor): row[0] = prefix + str(i) cursor.updateRow(row) prefix could be a parameter from your tool interface, or output from a function which returns the first two letters of the feaure type, or anything else for that matter, I'll leave that up to you though If AssetID field is already populated and you're just filling it in for a new row: prefix = 'SN' cursor = arcpy.da.UpdateCursor(file, ['AssetId']) no_asset_id = [r for r in cursor if r[0] is None][0] no_asset_id[0] = prefix + str(len(cursor)) cursor.updateRow(no_asset_id)
... View more
09-01-2016
04:01 PM
|
2
|
1
|
974
|
POST
|
Cursors can replace the CalculateField call to make it a bit clearer. with arcpy.da.UpdateCursor(file, ['group_code']) as cursor: for row in cursor: s = row[0] row[0] = "".join([c for c in s if c.isnumeric()]) cursor.updateRow(row) edit: forgot the updateRow call
... View more
09-01-2016
03:41 PM
|
2
|
0
|
203
|
Title | Kudos | Posted |
---|---|---|
1 | 11-23-2016 11:51 AM | |
1 | 11-28-2016 09:17 AM | |
1 | 12-08-2016 05:09 PM | |
1 | 07-27-2017 11:14 AM | |
1 | 11-10-2016 10:07 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|