|
POST
|
You made an interesting comment about just using the polygon feature in the SelectbyLocation rather than creating the in_memory feature class. This works too and I can take out that extra step of CreateFeatureClass_management and shave processing time right there. Thanks! Still interested in what might be wrong with the SelectbyLocation
... View more
09-29-2017
02:17 PM
|
0
|
2
|
5997
|
|
POST
|
I timed the: arcpy.CreateFeatureclass_management (.02 secs) arcpy.MakeFeatureLayer_management (2 secs) arcpy.SelectLayerByLocation_management (30 secs) I'm implementing a class: class Timer:
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
self.interval = self.end - self.start Then just messaging the print statement to see results for each arcpy method as such: t1 = Timer()
with t1:
fc2 = arcpy.CreateFeatureclass_management('in_memory', 'tmpFC', "POLYGON")
with arcpy.da.InsertCursor(fc2, ['SHAPE@']) as cur:
cur.insertRow([polygon])
msgt1 = "%s...CreateFeatureClass time %.02f seconds" % (bndy,t1.interval)
... View more
09-29-2017
01:59 PM
|
1
|
0
|
5997
|
|
POST
|
File Geodatabase (10.3) On a network share Spatial index applied Registered with ArcGIS Server (10.4) site Polygon: is quite simple maybe 25 vertices, an in_memory feature class that gets created from string input of rings, but clearly the SelectbyLocation is the culprit (timing each component): jsonFrmt = geo_convert(feature_info)
jsonData = json.loads(jsonFrmt)
inSr = arcpy.SpatialReference(3857)
for key,value in jsonData.iteritems():
if value == 'FeatureCollection':
pass
else:
for i in value:
for k,v in i.iteritems():
if k == 'geometry':
features = []
features2 = []
feature = v['coordinates']
polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]), inSr)
features.append(polygon)
else:
pass
fc2 = arcpy.CreateFeatureclass_management('in_memory', 'tmpFC', "POLYGON")
with arcpy.da.InsertCursor(fc2, ['SHAPE@']) as cur:
cur.insertRow([polygon])
pnt_fc = r'\\pathtonetworkfolder\myPointFeatureClass'
fl = "PointFeatures"
arcpy.MakeFeatureLayer_management(pnt_fc, "PointFeatures")
arcpy.SelectLayerByLocation_management(fl, "COMPLETELY_WITHIN", fc2)
rowcount = int(arcpy.GetCount_management(fl).getOutput(0))
if rowcount>0:
data.update({'HasPoints': 'yes'})
else:
data.update({'HasPoints': 'no'})
... View more
09-29-2017
01:49 PM
|
0
|
3
|
5997
|
|
POST
|
Being a bit greedy here, I know but has anyone come up with more efficient/faster alternatives to arcpy.SelectLayerByLocation_management? I'd say for the vast majority (ie. 99%) implementing this is entirely acceptable. However, I've run into a couple of instances lately that require several of these calls to be made in order to build a list/set of results that ultimately return an expected response. ...or in another instance, there are a large amount of point features (85 million) that need to be identified as COMPLETELY_WITHIN a simple single polygon feature. In most cases it's sub 30 seconds to return the expected result. However if these processes are to be published as synchronous GP services, the processing times can be excessive in that context. numpy? dictionaries? pandas? Anything at all that you may have tried to exceed the performance of arcpy.SelectLayerByLocation_management??? Case / scenario: select by location on points within a simple polygon feature and return a yes or no if the count is > 0
... View more
09-29-2017
11:46 AM
|
0
|
22
|
12004
|
|
DOC
|
No, compared to the Enhanced version, ESRI's widget seems to be correct.
... View more
09-27-2017
06:52 AM
|
0
|
0
|
18465
|
|
DOC
|
Ok thank you! The extra functionality is great but the lengths being calculated (when labeling with measurements) are way off and is problematic for users that rely on those values. Thanks again.
... View more
09-27-2017
06:46 AM
|
0
|
0
|
18465
|
|
DOC
|
Is anyone experiencing this same issue? The extra functionality is great with this widget but we cannot deploy it in applications if it is not functioning as expected.
... View more
09-27-2017
06:14 AM
|
0
|
0
|
18465
|
|
POST
|
Please mark Josua's post as the correct answer so other's will be able to see the resolution!
... View more
09-27-2017
05:47 AM
|
0
|
0
|
3457
|
|
POST
|
if variable = "SAM PLE NAME" then the string result will be "SAM PLE", not "SAMPLE". I was in response to what Joshua posted >>> variable = "SAMPLE NAME" >>> trunc = variable[:7].strip() >>> string = "'" + trunc + "'" >>> print string
... View more
09-26-2017
02:22 PM
|
0
|
1
|
1447
|
|
POST
|
You will still need to account for the possible conditions. This will work for "SAMPLE NAME". This will fail for "SAM PLE NAME" variable = "SAM PLE NAME"
trunc = variable[:7].strip()
string = "'" + trunc + "'"
... View more
09-26-2017
02:13 PM
|
0
|
3
|
1447
|
|
POST
|
I need to quit speedreading these OP's for little important details like that. heh.
... View more
09-26-2017
02:08 PM
|
1
|
0
|
3457
|
|
POST
|
I was under the impression that this also needs to account for "SAMPLE NAME" or "SAM PLE NAME"
... View more
09-26-2017
01:11 PM
|
1
|
7
|
1447
|
|
POST
|
The variable portion is what I'm trying to fix. If the space is left there, then there's an unnecessary space that we want to remove. Instead of "(SAMPLE_)", we need "(SAMPLE)", however, if the name so happens to be "SAM PLE" then we want to retain that space and end up with "(SAM_PLE)". I'm not entirely skilled in string manipulation and there's likely far better solution -- so this is quite limited in scope and would only account for the above scenario if the variable is "SAMPLE " or "SAM PLE NAME". But perhaps it might give you some ideas. truncVar = ""
variable = "SAM PLE NAME"
splitVarList = variable.split()
if len(splitVarList) < 3:
truncVar = splitVarList[0].strip()
elif len(splitVarList) == 3:
truncVar = "%s%s" % (splitVarList[0].strip(),splitVarList[1].strip())
print truncVar
... View more
09-26-2017
01:06 PM
|
0
|
0
|
5447
|
|
POST
|
One last thing to check is that the fields exist in your CalculateField_management parameters. I know sometimes fields get renamed or added to an output that is being merged with other data. And review the actual fieldname not just the alias for SAMPE_ID and FID. Other than that, only other time I've run into that 000732 is when I didn't have path references joined instead of fully qualified. Instead of this: #Merge all exported feature classes.
arcpy.env.workspace = sampfcdata
fclist = arcpy.ListFeatureClasses()
sampevents = "C:\\Projects\\CreateSamples\\SampleFeatureClasses\\Sample_Events"
arcpy.Merge_management(fclist, sampevents)
#Calculate SAMPLE_ID field.
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "") Implement this: #Merge all exported feature classes.
arcpy.env.workspace = sampfcdata
fclist = arcpy.ListFeatureClasses()
ws = r"C:\Projects\CreateSamples\SampleFeatureClasses"
fcname = r"Sample_Events"
sampvents = os.path.join(ws, fcname)
arcpy.Merge_management(fclist, sampevents)
#Calculate SAMPLE_ID field.
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "")
... View more
09-26-2017
12:42 PM
|
1
|
0
|
3457
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|