|
POST
|
Here is one I have used but the layer has to be in the same folder. project = arcpy.mp.ArcGISProject('CURRENT')
layer1 = project.listMaps()[0]
lyr = layer1.listLayers('HOMES')[0]
arcpy.env.workspace = os.path.dirname(project.filePath)
wp = os.path.dirname(project.filePath)
#lyr1 = project.listLayers("SUBJECT_PROPERTY")[0]
try:
cp = lyr.connectionProperties
cp['connection_info']['database'] = wp
cp['dataset'] = 'HOMES2.shp'
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
except:
pass
... View more
03-12-2021
01:52 PM
|
0
|
0
|
1515
|
|
POST
|
Wow that is pretty involved unfortunately I am not an supper advanced python scripture but I do appreciate the the code. I was thinking more along creating points for each polygon and then doing a spatial join back to the polygons and using the x,y spatial location to order/sort them to a specific order then how using a field calculator counter to update the attributes. I have been able to create points for each polygon and spatially joining them back to the polygons but lack creating the complexity of the field calculator.
... View more
01-15-2021
10:19 AM
|
0
|
0
|
2540
|
|
POST
|
Thank you for the reply and suggestion but i am not sure how to incorporate your suggestion.
... View more
01-13-2021
07:28 AM
|
0
|
0
|
2572
|
|
POST
|
I have created a fishnet and i need to updated the fields based on increments. Some of the sections need to increase from north to south and from east to west while others need to in crease from south to north and east west. Not really sure how to create the formula because I am not sure how I would write a script to tell it to auto-increment based on what I mentioned? I don't mind making small changes in a script to determine which filed I need and ranges i need to use.
... View more
01-12-2021
02:58 PM
|
0
|
5
|
2607
|
|
POST
|
I was able to achieve creating the blocks with the following below but would be nice if could have populate the attributes based on a formula and this is beyond me. I attached the sections in case anyone wants to help out. import arcpy, os
arcpy.env.overwriteOutput = True
def CreateFishnetsForFeats(shp, out, cell_x=0, cell_y=0, n_rows=0, n_cols=0):
# Create file gdb to store data
gdb = str(arcpy.CreateFileGDB_management(out, 'Fishnets.gdb').getOutput(0))
# spatial reference
arcpy.env.outputCoordinateSystem = arcpy.Describe(shp).spatialReference
# Loop thru rows of input polygons
with arcpy.da.SearchCursor(shp, ['SHAPE@', 'OID@']) as rows:
for row in rows:
ext = row[0].extent
st = '%f %f' %(ext.XMin, ext.YMin)
ort = '%f %f' %(ext.XMin, ext.YMax)
# Create fishnet
outFn = os.path.join(gdb, 'fish_{0}'.format(row[1]))
arcpy.CreateFishnet_management(outFn, st, ort, cell_x,cell_y, n_rows, n_cols,
labels='NO_LABELS',template = ext,
geometry_type='POLYGON')
# set workspace to new gdb
arcpy.env.workspace = gdb
fishnets = arcpy.ListFeatureClasses()
targ = fishnets[0]
for i, fish in enumerate(fishnets):
# Add field for original polygon ID
fid = fish.split('_')[1]
arcpy.AddField_management(fish, 'POLY_ID', 'LONG')
with arcpy.da.UpdateCursor(fish, ['POLY_ID']) as rows:
for row in rows:
row[0] = fid
rows.updateRow(row)
# append fishnets into one feature class
if i > 0:
arcpy.Append_management([fish], targ, 'NO_TEST')
arcpy.Delete_management(fish)
print (*'Appended: {0}'.format(fish))
print ('Done')
return
if __name__ == '__main__':
polys = r'C:\Temp\SectionGrid\SectionsCopy.shp'
loc = r'C:\TEMP'
CreateFishnetsForFeats(polys, loc, 0, 0, 9, 9)
... View more
01-08-2021
10:36 AM
|
0
|
0
|
615
|
|
POST
|
Surely I am not the only one that has need to do this and I was hopping there would be something automated since what you describe would be time consuming but I appreciate the suggestion.
... View more
01-07-2021
02:35 PM
|
0
|
2
|
3251
|
|
POST
|
I have been messing the fishnet tool for a while and can't produce what i need. I am thinking that some how each section length & high has to be calculated then divided evenly by 9 times?
... View more
01-06-2021
01:59 PM
|
0
|
4
|
3268
|
|
POST
|
This would be used as an addressing grid. The blue lines would be a whole section. Range - address range, increase from right to left and south to north. I guess I just need each sections to be broken into just 9 sections not 100. The increase from right to left is just a 1000 of possible addresses. Hopefully that helps.
... View more
01-06-2021
01:21 PM
|
0
|
1
|
3273
|
|
POST
|
I need to create a polyline grid with vertical and horizontal lines of increments of one hundred, somehow divide each polyline/polygon by 9 and across multiple polygons/polylines and I am not sure on how go about doing it. What I have is the polygons/sections and polylines/sections lines.. The polygons/polylines are NOT evenly squared so I can't use fish net, at least I don't think...?
... View more
01-06-2021
10:45 AM
|
1
|
11
|
3920
|
|
POST
|
Trying to figure out how to populate two fields based on two fields. I need to be able to populate say F_ID3 with the number of occurrences of F_ID1 then in F_D4 add the text of the occurrences from F_ID2. Like below, note that their may be empty or nulls in the fields Currently have this OBJECTID F_ID1 F_ID2 1 aa1123 12345 2 aa1123 12346 3 BB3361 67891 4 BB3361 67892 5 BB3361 67893 6 UU9832 11123 7 PP2225 6989 8 PP2225 6988 I need this OBJECTID F_ID1 F_ID2 F_ID3 F_ID4 1 aa1123 12345 2 12345, 12346 2 aa1123 12346 3 BB3361 67891 3 67891, 67892, 37893 4 BB3361 67892 5 BB3361 67893 6 UU9832 11123 1 11123 7 PP2225 6989 2 6988, 6989 8 PP2225 6988
... View more
10-15-2020
08:41 AM
|
0
|
2
|
784
|
|
POST
|
Not sure why I didn't think of that big give away "field is not nullable."
... View more
09-21-2020
11:10 AM
|
0
|
0
|
1596
|
|
POST
|
I get "There was a failure during processing". Error 999999 & the field is not nullable. Some rows do have zero if both fields.
... View more
09-21-2020
10:40 AM
|
0
|
2
|
1596
|
|
POST
|
Ya I could have done it that way but I want to know who to do it through field calculator.
... View more
09-21-2020
08:42 AM
|
0
|
0
|
1596
|
|
POST
|
I need to calculate ratio between two numbers than to percent but some rows in both field1 and field2 have zero values. Simple calculator field2 / field1 * 100 but field1 has zeros, how do I by pass the rows with zeros in field1 in field calculator? Field 1 field 2 0 15200 --> can't divide 0/15200
... View more
09-21-2020
08:23 AM
|
0
|
6
|
1821
|
|
POST
|
The first time I was using 2.y python, which worked yesterday but today nothing happens when I run the script, no error no output .xlsx.and I didn't change anything, I am lost on this one. So i decided to try it on 3.6 so in 3.6 I have to add from importlib import reload and comment out sys.setdefaultencoding('Cp1252') but in doing so I get the same error, on line 17 'utf8' codec can't decode byte 0xc3 in position 0: invalid continuation byte. Thoughts? mport pyodbc
import pandas as pd
import os
from importlib import reload
reload(sys)
#sys.setdefaultencoding('Cp1252')
cnxn = pyodbc.connect("Driver={SQL Server};"
"Server=***;"
"Database=***;"
"uid=***;pwd=***")
cursor = cnxn.cursor()
script = """
SELECT * FROM ***.***
"""
df = pd.read_sql(script, cnxn)
writer = pd.ExcelWriter(r'C:\Temp\export.xlsx')
df.to_excel(writer, sheet_name ='Sheet1', encoding='utf-8')
writer.save()
... View more
07-14-2020
11:31 AM
|
0
|
1
|
2136
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2022 11:37 AM | |
| 1 | 10-31-2023 10:16 AM | |
| 1 | 02-16-2023 01:50 PM | |
| 1 | 08-11-2021 11:13 AM | |
| 1 | 01-06-2021 10:45 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-10-2024
10:42 AM
|