POST
|
hi Tray will you able to post your code to jsfiddle, please. I am seeking the same solution. Thanks alot
... View more
07-23-2015
07:48 AM
|
0
|
1
|
559
|
POST
|
Jay How did you resolve this issue without using ArcGIS Geoprocessing Service? The example Jeff Jacobson provided is no longer available. Many Thanks
... View more
06-11-2015
12:09 PM
|
0
|
0
|
2022
|
POST
|
http://jsbin.com/sapipeyewi/1/ The feature table can only be shown correctly in the floating pane when it is first time clicked. There are two issues I confused. 1) if close the floating pane, nothing will happen if clicking on the button "Township" 2) if hide the floating pane, the feature table is displayed beyond the size of float pane when clicking on the button "Township" Thanks for your help~
... View more
01-15-2015
10:49 AM
|
0
|
2
|
3661
|
POST
|
Is there solution to this issue? Esri??? I am using the the aerial imagery from another server as the base map for my map service. It is normal to dislay the labels in feature layer but have halo behind all labels when overplapping with that imagery. Any ideas of this? Thanks
... View more
05-29-2013
06:45 AM
|
0
|
0
|
269
|
POST
|
Part 2
else:
CX = Clustlst[0][5]
CY = Clustlst[0][6]
CDir = Clustlst[0][7]
print "Scount:", Scount, "ClusterID",IDcount, "X", CX, "Y",CY
Scount=Scount+1
k = 0
while k <len(Clustlst):
row=ptCursor.newRow()
point = arcpy.CreateObject('POINT')
point.X=CX
point.Y=CY
row.Shape=point
row.ClusterID = IDcount
row.C_LON_X = CX
row.C_LAT_Y = CY
row.C_Bearing = CDir
row.NearbyPtID = Clustlst [4]
row.NearbyLON_X = Clustlst [5]
row.NearbyLAT_Y = Clustlst [6]
row.NearbyBearing = Clustlst [7]
ptCursor.insertRow(row)
k=k+1
InFIDlst=[]
NearFIDlst=[]
NearXlst=[]
NearYlst=[]
NearBearinglst=[]
TargetXlst=[]
TargetYlst=[]
TargetBearinglst=[]
TargetRouteIDlst=[]
TargetTracelst=[]
IDcount = IDcount+1
elif currentINFID!= prevINFID or not ccur:
InFIDlst=[]
NearFIDlst=[]
NearXlst=[]
NearYlst=[]
NearBearinglst=[]
TargetXlst=[]
TargetYlst=[]
TargetBearinglst=[]
TargetRouteIDlst=[]
TargetTracelst=[]
Rcount = Rcount+1
if ccur:
tmp1=ccur.getValue('NEAR_FID')
tmp2=ccur.getValue('IN_FID')
if tmp1 in Reduncelst and tmp2 not in Reduncelst:#To compare before adding a point and avoid centers in "Rcount" Siling
comparecur = arcpy.SearchCursor(result)
for compcur in comparecur:
if compcur.NearbyPtID == ccur.NEAR_FID:
dist2 = math.sqrt((compcur.getValue('NearbyLON_X') - compcur.getValue('C_LON_X'))**2+(compcur.getValue('NearbyLAT_Y') - compcur.getValue('C_LAT_Y'))**2)
dist1 = math.sqrt((compcur.getValue('NearbyLON_X')-ccur.getValue('LON_X'))**2+(compcur.getValue('NearbyLAT_Y')-ccur.getValue('LAT_Y'))**2)
if dist1<dist2:
arcpy.MakeTableView_management(result,"tempViewSection01ClusSample")
arcpy.SelectLayerByAttribute_management("tempViewSection01ClusSample","NEW_SELECTION",'"NearbyPtID" =%i' %compcur.NearbyPtID)
arcpy.DeleteRows_management("tempViewSection01ClusSample")
InFIDlst.append(ccur.getValue('IN_FID'))
NearFIDlst.append(ccur.getValue('NEAR_FID'))
NearXlst.append(ccur.getValue('NEAR_X'))
NearYlst.append(ccur.getValue('NEAR_Y'))
NearBearinglst.append(ccur.getValue('Bearing_1'))
TargetXlst.append(ccur.getValue('LON_X'))
TargetYlst.append(ccur.getValue('LAT_Y'))
TargetBearinglst.append(ccur.getValue('Bearing'))
TargetRouteIDlst.append(ccur.getValue('RouteId'))
TargetTracelst.append(ccur.getValue('Trace'))
elif tmp2 not in Reduncelst: #avoid adding if this is a center in "Rcount" to improve performance.
InFIDlst.append(ccur.getValue('IN_FID'))
NearFIDlst.append(ccur.getValue('NEAR_FID'))
NearXlst.append(ccur.getValue('NEAR_X'))
NearYlst.append(ccur.getValue('NEAR_Y'))
NearBearinglst.append(ccur.getValue('Bearing_1'))
TargetXlst.append(ccur.getValue('LON_X'))
TargetYlst.append(ccur.getValue('LAT_Y'))
TargetBearinglst.append(ccur.getValue('Bearing'))
TargetRouteIDlst.append(ccur.getValue('RouteId'))
TargetTracelst.append(ccur.getValue('Trace'))
prevINFID = currentINFID
ccur = Currcur.next()
pcur = Prevcur.next()
del ccur,Currcur, pcur,Prevcur,row, ptCursor,tcur, tempcur,compcur, comparecur
print "Elapsed Time:", time.clock() - t0, "Seconds", "IDcount=", IDcount, "Rcount=", Rcount, "Scount=", Scount
... View more
03-26-2012
03:51 PM
|
0
|
0
|
228
|
POST
|
Part 1
import arcpy
import math
import time
arcpy.env.workspace=r'C:\TempArcGISCalculate\Scratch.gdb'
arcpy.env.overwriteOutput = True
t0=time.clock()
OriginNearTable="Section01Smoothed2_GenerateN"
NearTable = "TableView_Section01Smoothed2_GenerateN"
arcpy.MakeTableView_management(OriginNearTable, NearTable)
result = "Section01ClusterSample11"
arcpy.CreateFeatureclass_management("C:/TempArcGISCalculate/Scratch.gdb", result,"POINT","","","", "C:\TempArcGISCalculate\WGS_1984_UTM_Zone_17N.prj")
arcpy.AddField_management(result, "ClusterID","LONG")
arcpy.AddField_management(result, "C_LON_X","DOUBLE")
arcpy.AddField_management(result, "C_LAT_Y","DOUBLE")
arcpy.AddField_management(result, "C_Bearing","DOUBLE")
arcpy.AddField_management(result, "NearbyPtID","LONG")
arcpy.AddField_management(result, "NearbyLON_X","DOUBLE")
arcpy.AddField_management(result, "NearbyLAT_Y","DOUBLE")
arcpy.AddField_management(result, "NearbyBearing","DOUBLE")
ptCursor = arcpy.InsertCursor(result)
InFIDlst=[]
NearFIDlst=[]
NearXlst=[]
NearYlst=[]
NearBearinglst=[]
TargetXlst=[]
TargetYlst=[]
TargetBearinglst=[]
TargetRouteIDlst=[]
TargetTracelst=[]
Reduncelst =[]
Currcur = arcpy.SearchCursor(NearTable) # Current Cursor for field: IN_FID
Prevcur = arcpy.SearchCursor(NearTable) # Previous Cursor for field: IN_FID
ccur = Currcur.next()
pcur = Prevcur.next()
prevINFID = ccur.getValue('IN_FID')
InFIDlst.append(ccur.getValue('IN_FID'))
NearFIDlst.append(ccur.getValue('NEAR_FID'))
NearXlst.append(ccur.getValue('NEAR_X'))
NearYlst.append(ccur.getValue('NEAR_Y'))
NearBearinglst.append(ccur.getValue('Bearing_1'))
TargetXlst.append(ccur.getValue('LON_X'))
TargetYlst.append(ccur.getValue('LAT_Y'))
TargetBearinglst.append(ccur.getValue('Bearing'))
TargetRouteIDlst.append(ccur.getValue('RouteId'))
TargetTracelst.append(ccur.getValue('Trace'))
ccur=Currcur.next()
flag=0
IDcount = 1 # Cluster ID
Rcount = 0 # To count number of target point which is already to be neighoubr of other points
Scount = 0 #
while pcur:
if ccur:
currentINFID = ccur.getValue('IN_FID')
else:#When it reached the end of the file
currentINFID = -1
if prevINFID not in Reduncelst and (currentINFID!= prevINFID or not ccur):
Clustlst=[]
n = len(InFIDlst)
Clustlst.append((pcur.getValue('IN_FID'),pcur.getValue('LON_X'),pcur.getValue('LAT_Y'),pcur.getValue('Bearing'),pcur.getValue('IN_FID'),pcur.getValue('LON_X'),pcur.getValue('LAT_Y'),pcur.getValue('Bearing')))
if n<>0: # avoid Clustlst = [] meaning the neighbor points of the target point in IN_FID are used by other target points
for i in range(n):
Clustlst.append((InFIDlst,TargetXlst,TargetYlst,TargetBearinglst,NearFIDlst, NearXlst,NearYlst,NearBearinglst))
if NearFIDlst not in Reduncelst:
Reduncelst.append(NearFIDlst)
TX = 0.0
TY = 0.0
TDir = 0.0
CX = 0.0
CY = 0.0
CDir = 0.0
for j in range(len(Clustlst)):
TX = TX + Clustlst [5]
TY = TY + Clustlst [6]
TDir = TDir + Clustlst [7]
CX=TX/len(Clustlst)
CY=TY/len(Clustlst)
CDir =TDir/len(Clustlst)
#Make a in-memory table to store all the points related to the point in current cluster
arcpy.SelectLayerByAttribute_management(NearTable, "NEW_SELECTION", "IN_FID in (" + str(NearFIDlst)[1:-1] + ")") # when NearFIDlst !=[]
arcpy.CopyRows_management(NearTable, "in_memory/selectedpoints")
tempcur = arcpy.SearchCursor("in_memory/selectedpoints")
#See if there is any points not included in current cluster
for tcur in tempcur: # Search neighbor point's neighbor
if tcur.NEAR_FID in NearFIDlst or tcur.NEAR_FID==InFIDlst[0]: # if the neighbor of the target's neighbor point is already included or the neighbor of the target's neighor point is the target itself
continue # ignore it and then continue
elif ((tcur.NEAR_X-CX)**2+(tcur.NEAR_Y-CY)**2)<= 16: # if the neighbor of the target's neighbor point is within the 4-m buffer of the preliminary cluster center
comparecur = arcpy.SearchCursor(result)
for compcur in comparecur: # Search classified points represented by the generated cluster center
#When {pi} is found in the "Section01ClusterSample"
if compcur.NearbyPtID == tcur.NEAR_FID: # if the neighbor of the target's neighbor point is already represented by one final cluster center
# Compare distances from the neighbor of the target's neighbor point to that final cluster center and the preliminary cluster center
dist2 = math.sqrt((compcur.getValue('NearbyLON_X') - compcur.getValue('C_LON_X'))**2+(compcur.getValue('NearbyLAT_Y') - compcur.getValue('C_LAT_Y'))**2)
dist1 = math.sqrt((compcur.getValue('NearbyLON_X')-CX)**2+(compcur.getValue('NearbyLAT_Y')-CY)**2)
if dist1<dist2:
arcpy.MakeTableView_management(result,"tempViewSection01ClusSample")
arcpy.SelectLayerByAttribute_management("tempViewSection01ClusSample","NEW_SELECTION",'"NearbyPtID" =%i' %compcur.NearbyPtID)
arcpy.DeleteRows_management("tempViewSection01ClusSample")
flag = 1 #flag state 1 means {pi} closer to current siling (--- preliminary cluster center)
break
else:
flag = 2 #flag state 2 means {pi} closer to original siling (--- the final cluster center)
break
else:
flag = 0 # if no compcur.NearbyPtID qualified as tcur.NEAR_FID (zhao ren, mei zhao dao, meizhaodao, meizhaodao...), go to step: if flag<>2
#flag state 0 means {pi} not presented by any siling
if flag<>2:
Clustlst.append((Clustlst[0][0], Clustlst[0][1],Clustlst[0][2],Clustlst[0][3],tcur.NEAR_FID,tcur.NEAR_X,tcur.NEAR_Y,tcur.Bearing_1))
if tcur.NEAR_FID not in Reduncelst:
Reduncelst.append(tcur.NEAR_FID)
... View more
03-26-2012
03:51 PM
|
0
|
0
|
228
|
POST
|
Hi, python Supermen, I got a pseudo code as described below. I am trying to make it works, but running is really slow. Please help to facilitate it if you dont mind. The input table is as shown in attachment.
C = 0 (set of rep. points = empty)
for sj in S: (All GPS points involved in all trajectories)
find points are within (4m) to sj & are not represented by any rep. in C
calculate the centroid c*1 of these points
if no points are within (4m) to sj, then sj will represent itself (or marked as outlier/noise to be removed later)
find points (k) are within (2m) to c*1
for sk in k
if sk is not represented
assign sk to c*1
if sk is represented by c*2
compare distances dk1 & dk2
if dk1 < dk2
assign sk to c*1
If all neighbors of sk are represented, then randomly choose sj from the remaining un-represented points
Iterate until all sj are represented
C stores all rep. point (structure: C:[Id, Pc_X, Pc_Y, dir, ncp:{all pts within 2m (less or equal to) of c*i}] s) *
... View more
03-26-2012
03:47 PM
|
0
|
2
|
385
|
POST
|
I have a script to run distance-based point clustering. it takes almost 4 mins to finish only 600 pts. do you mind to have a look? help me to facilitate the process?
... View more
03-20-2012
10:21 AM
|
0
|
0
|
139
|
POST
|
My question is: which one is faster, using Query in SearchCursor or SelectlaybyAttribute to retrieve desired values from table in file geodatabase?
... View more
03-20-2012
09:59 AM
|
0
|
2
|
389
|
POST
|
NearFIDlst = [33950, 7700, 4340] I try to make a search query based on the values in the list NearFIDlst.
f=0
while f <len(NearFIDlst):
Query = '"IN_FID"' +'='+ "'" + NearFIDlst + "'"
tempcur = arcpy.SearchCursor(NearTable, Query)
tcur = tempcur.next() the feedback keeps telling "TypeError: cannot concatenate 'str' and 'int' objects" when I change the Query to: Query = '"IN_FID"' + " = '" + str(NearFIDlst ) + "'" it gives me "RuntimeError: ERROR 999999: Error executing function." please help~~, Thanks lot
... View more
03-19-2012
08:32 AM
|
0
|
3
|
456
|
POST
|
Is there any one had such problem before? I use Generate Near Table to find points within 4 m of the target point. Input Features and Near Features are the same feature class. the result give me different locations of near features. Since I already removed all duplicated/identical points which have same x and y, the near table should not give me NEAR_DIST = 0. Unfortunately, it still did.
... View more
03-15-2012
06:54 PM
|
0
|
0
|
353
|
POST
|
Thanks for the narative. So I think you can: 1. Buffer your points 2. Run an Identity (or Intersect) tool on your points and buffer polygon - This will "tag" each point with what point buffer it is within - be carefull because you will end up with duplicate points where the buffer polygons overlap!!! 3. In a cursor (maybe helpfull to use a Python dictionary to sort out some of the realtionships) - use the Intersect/Identity tabular information (x/y/point_id/buffer_id) to analyze the realtionships. Run a small sample area of your point and point buffers through the Identity or Intersect tools to see what can be done with the output table info. A recursive SelectByLocation will be extreemly slow compared with the convetional Intersect or Identity tools. Here is my code using Intersect_analysis instead of SelectLayByLocation
import arcpy, time
arcpy.env.workspace = r'C:\TempArcGISCalculate\TempFile\TestforReadingFile'
arcpy.env.overwriteOutput=True
ptfc = 'Section01_SplitedTrips.shp'
t0=time.clock()
arcpy.Buffer_analysis(ptfc,'in_memory/Section01Buffer','4 meters')
arcpy.MakeFeatureLayer_management('in_memory/Section01Buffer','S1buffer')
ptCurs=arcpy.SearchCursor('S1buffer')
ptcur = ptCurs.next()
count = 1
while ptcur:
selPoly=arcpy.SelectLayerByAttribute_management('S1buffer',"NEW_SELECTION","\"FID\"="+str(ptcur.FID))
themeList=['S1buffer',ptfc]
arcpy.Intersect_analysis(themeList,'in_memory/points_within_buffers')
bufPts = 'in_memory/points_within_buffers'
PtCount = arcpy.GetCount_management(bufPts)
curs = arcpy.SearchCursor(bufPts)
print PtCount
for cur in curs:
print count, cur.getValue('LON_X')," ", cur.getValue('LAT_Y')
del cur,curs
ptcur = ptCurs.next()
count = count + 1
if count>10:
break
del ptcur, ptCurs
print "Elapsed time: " , time.clock() - t0
I use 10 sample data points for both script. the results are same. However, the Intersect takes 39.5106703156 secs; SelectLayByLocation takes 9.16266229449 sec Could you please have a look at the Intersect one, please?
... View more
03-08-2012
04:28 PM
|
0
|
0
|
242
|
POST
|
Anything is possible... Can you give a narative description of what this code is doing? Looks like it is attempting to define some sort of 'spatial association' - like identifying the points within the buffer of a polygon. Maybe a conventional overlay tool would better serve this purpose... For example, Intersect (Intersect tool) your polygons buffers with your points and cursor through that output. Sorry for making you confuse. I restate my problem again.
... View more
03-08-2012
03:45 PM
|
0
|
0
|
242
|
POST
|
I have a point shapefile wihch has 527k data points. 1st step: I am trying to create a 4 meters buffer at each points to find its neighbours and corresponding information (such as X, Y, direction) within the buffer. 2nd step: To identify the points which fall in the overlapping area of two or more buffer, and assign them to their real buffer by comparing distances to each buffer's center 3rd step: Using all points (including the focal point) within the buffer to calculate average position (avg_X and avg_Y) and avg_Direction. 4th step: change the buffer point's x, y and direction to the avg_X, avg_Y, and avg_Direction. Following code is for the 1st step import arcpy, math
arcpy.env.workspace = r'C:\TempArcGISCalculate\TempFile\TestforReadingFile'
arcpy.env.overwriteOutput=True
ptfc = 'Section01_SplitedTrips.shp'
arcpy.MakeFeatureLayer_management(ptfc,'section01pts')
arcpy.Buffer_analysis(ptfc,'in_memory/Section01Buffer','4 meters')
arcpy.MakeFeatureLayer_management('in_memory/Section01Buffer','S1buffer')
#Cut out points inside each buffer
rows = arcpy.SearchCursor('in_memory/Section01Buffer')
row = rows.next()
count = 1
try:
while row:
selPoly =arcpy.SelectLayerByAttribute_management('S1buffer',"NEW_SELECTION","\"FID\"="+str(row.FID))
selPts = arcpy.SelectLayerByLocation_management('section01pts',"WITHIN",selPoly, 0, "NEW_SELECTION")
curs = arcpy.SearchCursor(selPts)
for cur in curs:
print count, cur.getValue('LON_X')," ", cur.getValue('LAT_Y')," ", cur.getValue('InitialBea')," ", cur.getValue('Trace')," ", row.getValue('LON_X'), " ", row.getValue('LAT_Y'), " ", row.getValue('Trace')
del cur,curs
row =rows.next()
count = count + 1
del row, rows
except Exception, e:
#If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "line %i" % tb.tb_lineno
print e.message
Q1: Is it possible to make this process faster? it is ok for dataset which has row less than 1000, but takes longer as more date involved Q2: When I add " print arcpy.AddMessage("Elapsed time: " + str(time.clock() - beginTime))" before "del row, rows", It always tells below. This command used to be ok for my previous script. Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript exec codeObject in __main__.__dict__ File "C:\TempArcGISCalculate\PythonScript\SelectbyLocation.py", line 31, in <module> arcpy.AddMessage("Elapsed time: " + str(time.clock() - beginTime)) NameError: name 'time' is not defined
... View more
03-08-2012
02:07 PM
|
0
|
6
|
373
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|