|
POST
|
Sorry, forgot to mention... I took your sample data for the expression. In your real expression, you should of course load the featureset from your portal. So instead of lines 2&3 in my code above, you would do something like this: var fs = FeaturesetByPortalItem(
Portal("https://my-server.de/portal"), // your Portal's url
"bb11a82308a5439291c17a477755d27a", // the service id
0, // the sub-layer id
["*"], // the fields you want to load
false // do you want to load geometries
) You can get all the neccessary arguments from your table's url:
... View more
12-02-2022
12:42 AM
|
1
|
2
|
3514
|
|
POST
|
// load data
var input = {fields: [{name: "Site", type: "esriFieldTypeString"}, {name: "Species1", type: "esriFieldTypeString"}, {name: "Species1Obs", type: "esriFieldTypeInteger"}, {name: "Species2", type: "esriFieldTypeString"}, {name: "Species2Obs", type: "esriFieldTypeInteger"}, {name: "Species3", type: "esriFieldTypeString"}, {name: "Species3Obs", type: "esriFieldTypeInteger"},], features: [{attributes: {Site: "Little Swamp", Species1: "Red Kangaroo", Species1Obs: 5, Species2: "Wallaby", Species2Obs: 3, Species3: "Eastern Grey", Species3Obs: 10}}, {attributes: {Site: "Big Swamp", Species1: "Fox", Species1Obs: 5, Species2: "Red Kangaroo", Species2Obs: 10, Species3: "Eastern Grey", Species3Obs: 5}},], geometryType: ""}
var fs = Featureset(Text(input))
// flatten the table
var flat_dict = {
fields: [
{name: "Species", type: "esriFieldTypeString"},
{name: "Obs", type: "esriFieldTypeInteger"},
],
features: [],
geometryType: ""
}
var max_species_number = 3
for(var f in fs) {
for(var i = 1; i <= max_species_number; i++) {
var new_f = {attributes: {Species: f[`Species${i}`], Obs: f[`Species${i}Obs`]}}
Push(flat_dict.features, new_f)
}
}
var flat_fs = Featureset(Text(flat_dict))
// group by species and return
return GroupBy(flat_fs, ["Species"], [{name: "Obs", expression: "Obs", statistic: "SUM"}])
... View more
11-30-2022
11:28 PM
|
0
|
4
|
3533
|
|
POST
|
Your first script fails because you forgot the index in the failing line. So you're trying to use the non-existing union method of an array (row) instead of the geometry (row[0]). But the script would fail there anyway, because arcpy.management.CopyFeatures() does not what you think it does. You seem to want to extract the geometries, but this tool copies a feature class from one location to another. You got the gist of what you need to do: Extract the geometries Iterate over the rows with an UpdateCursor union the current geometry with all extracted geometries write it into the feature class optionally: you probably should delete every row after the first one, so you don't get overlapping features. zones = "TestPolygons" # layer name or fc path
zone_name_field = "TextField" # name of the field that determines the "sameness"
only_keep_first = True # only keep the first row of each zone, delete the following rows
zone_names = ["A"] # Names you want to union
# You can also do it automatically for every zone name:
#zone_names = {r[0] for r in arcpy.da.SearchCursor(zones, [zone_name_field])}
for zone_name in zone_names:
sql = f"{zone_name_field} = '{zone_name}'"
# extract the geometries into a list
zone_geometries = [r[0] for r in arcpy.da.SearchCursor(zones, ["SHAPE@"], sql)]
first_row = True
# iterate over the fc
with arcpy.da.UpdateCursor(zones, ["SHAPE@"], sql) as cursor:
for r in cursor:
if first_row:
# union the current geometry with every extracted geometry
geo = r[0]
for other_geo in zone_geometries:
geo = geo.union(other_geo)
cursor.updateRow([geo])
# delete the following rows if only_keep_first == True
first_row = not only_keep_first
else:
cursor.deleteRow() Before: With only_keep_first == True: With only_keep_first == False:
... View more
11-29-2022
10:38 PM
|
3
|
0
|
3952
|
|
POST
|
11-29-2022
12:21 AM
|
2
|
1
|
1476
|
|
POST
|
Your code works perfectly for me. What problems do you encounter?
... View more
11-28-2022
01:33 AM
|
2
|
1
|
2701
|
|
IDEA
|
There is a "Select All" button, but it could be more obvious and user friendly. Recognize Button 1? It's the same as in Excel, except for the annoying fact that you have to press Shift while clicking it to select all rows. I guess they did it that way because it has a second mode: Ctrl clicking it will switch the selection. So in my opinion, the Idea should be "Make this button Select All without keyboard modifier, and maybe give it a tooltip." For completeness, Here are some ways to select all rows Ctrl + A Shift + Button 1 If no rows are selected yet, you can switch the selection Button 2 Ctrl + U Ctrl + Button 1 While it is very slow compared to the other options, you can also use Select By Attributes with a true statement like "1 = 1" or "ObjectID = ObjectID"
... View more
11-24-2022
11:58 PM
|
0
|
0
|
7848
|
|
POST
|
Then you should be able to use this simple script in ArcGIS Pro's Python Window: # edit these variables
layer_name = "Layer"
output_folder = "N:/.../temp"
from pathlib import Path
attachment_table = arcpy.Describe(layer_name).catalogPath + "__ATTACH"
with arcpy.da.SearchCursor(attachment_table, ["DATA", "ATT_NAME"]) as cursor:
for data, name in cursor:
print(f"currently exporting {name}")
out_file = Path(output_folder, name)
out_file.write_bytes(data)
... View more
11-24-2022
06:48 AM
|
0
|
4
|
7159
|
|
POST
|
I'm sorry to say that I have no idea what could be the case. Maybe @HusseinNasser2 can help?
... View more
11-24-2022
06:23 AM
|
0
|
0
|
6451
|
|
POST
|
Are we talking about an actual Attachment Table, which is created with the Attachment tools and managed by ArcGIS? Or are we talking about a "normal" feature class with a field that contains a file path?
... View more
11-24-2022
02:11 AM
|
0
|
6
|
7180
|
|
POST
|
This looks as if you have not actually created the feature yet. The attribute rule doesn't trigger when you put the point in, only when you finish the feature creation. In the feature creation window: The FUID isn't there, because the rule didn't trigger yet. After I clicked on "Hinzufügen" ("Add"): Now the rule did trigger, and the FUID is calculated.
... View more
11-23-2022
11:50 PM
|
0
|
2
|
6455
|
|
POST
|
Glad that you got it to work. Who knew right? Almost nobody. This is a problem that regularily trips up users both new and experienced. It's a completely illogical design decision that noone expects (and neither should they). I'm just gonna plug my Idea about this here, I'm glad for everyone that lends their support to it: Arcade: Allow Date() values in date fields (esriFi... - Esri Community
... View more
11-23-2022
11:16 PM
|
2
|
0
|
3820
|
|
POST
|
You have to check if the field is already filled at the start. If yes, just return that value. Also, your rule can be simplified a bit: // if this feature already has a fuid, return that
if(!IsEmpty($feature.FUID)) { return $feature.FUID }
// get the feature with the greatest fuid in the featureset
var fuid_features = Filter($featureset, "FUID IS NOT NULL")
var max_fuid_feature = First(OrderBy(fuid_features, "FUID DESC"))
// for an empty featureset, this will be null, so return the first fuid
if(max_fuid_feature == null) { return "EOC00001" }
// calculate and return the next fuid
var max_fuid = max_fuid_feature.FUID
var next_fuid_number = Number(Replace(max_fuid, "EOC", "")) + 1
return "EOC" + Text(next_fuid_number, "00000")
... View more
11-23-2022
12:36 AM
|
0
|
4
|
6467
|
|
POST
|
Hello I am looking for tutorials for layout from start to finish My thanks in advance The official documentation: Mises en page dans ArcGIS Pro—ArcGIS Pro | Documentation A tutorial on Youtube: Getting Started with ArcGIS Pro: Building a Layout - YouTube
... View more
11-22-2022
01:50 AM
|
2
|
1
|
1534
|
|
POST
|
There are ways, yes. The easiest way would be to find the author of the map (someone in the U.S. Department of Agriculture) and ask them for the source data. These people don't bite, and the worst they can do is say no 🙂 Extracting the points yourself leads you into quite advanced topics, which are probably way out of scope for a school project. But, for the sake of an example, I'll show one way to do it: Luckily, the map you found is not in fact a png, but a pdf with vector data. You can recognize that by zooming in. If the content of the map gets pixely, it is a raster image (eg a png, jpg, gif, whatever). If it redraws at the new scale, it's vector data. We can extract vector data from the pdf to load it into ArcGIS and further process it there. You can do that with Incscape, or by converting the pdf to a dxf file. There are many online converters available, they all produce different outputs. In this case, I got usable results with onlineconvertfree. So, convert the pdf to dxf and load that file into ArcGIS Pro: The dxf file actually contains multiple layers with the different geometry types. Sadly, the points of your map aren't actually stored as points, but as polygons. So we will have to convert them. Also, the data doesn't have a coordinate system, so we have to do something about that. Let's take a look at the pdf and see if there is anything in there about the coordinate system. We'll do this in Python. import PyPDF2
from pprint import pprint
# read the first (and only) page of the pdf
pdf = "N:/bla/cattle_map.pdf"
reader = PyPDF2.PdfFileReader(pdf)
page = reader.pages[0]
# let's take a look
pprint(page)
#{'/Contents': IndirectObject(1, 0),
# '/MediaBox': [0, 0, 792, 612],
# '/Parent': IndirectObject(37, 0),
# '/Resources': IndirectObject(28, 0),
# '/Type': '/Page',
# '/VP': [{'/BBox': [58.20162, 469.49288, 692.41922, 43.1716],
# '/Measure': IndirectObject(31, 0),
# '/Name': 'US Data Frame',
# '/Type': '/Viewport'},
# {'/BBox': [54.0015, 575.9982, 212.4059, 475.19317],
# '/Measure': IndirectObject(33, 0),
# '/Name': 'AK Data Frame',
# '/Type': '/Viewport'},
# {'/BBox': [54.0015, 97.17429, 144.004, 35.97124],
# '/Measure': IndirectObject(35, 0),
# '/Name': 'HI Data Frame',
# '/Type': '/Viewport'}]}
# The /VP key looks interesting. It includes the viewports for the continental US; Alaska, and Hawaii. Let's look at the US. The Measure parameter is still hidden.
pprint(page["/VP"][0]["/Measure"])
#{'/Bounds': [0, 1, 0, 0, 1, 0, 1, 1],
# '/GCS': IndirectObject(30, 0),
# '/GPTS': [21.6176,
# -118.83703,
# 48.90833,
# -128.98979,
# 49.20632,
# -64.25761,
# 21.82903,
# -74.06214],
# '/LPTS': [0, 1, 0, 0, 1, 0, 1, 1],
# '/Subtype': '/GEO',
# '/Type': '/Measure'}
# GCS is the abbreviation of Geographic Coordinate System. That should be what we're after.
pprint(page["/VP"][0]["/Measure"]["/GCS"])
#{'/Type': '/PROJCS',
# '/WKT': 'PROJCS["USA_Custom_Albers_Equal_Area_Conic_US",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Statute_Mile",1609.344]]'}
# Yep, there's the definition of the coordinate system. Let's store that in a variable.
wkt = page["/VP"][0]["/Measure"]["/GCS"]["/WKT"] Now that we know the coordinate system, lets apply it to the map: active_map = arcpy.mp.ArcGISProject("current").activeMap
active_map.spatialReference = arcpy.SpatialReference(text=wkt) The coordinates in the pdf are wrong, so we need to georeference the dxw layer. Now we can extract the polygons. There are probably good reasons for the custom projection, but it might be better to change the projection to something more widely used. I'm using WGS 84 here, which is the standard system used in GPS. We don't need to project every layer, only the "Polygon Group / C1E-64-B3" layer, which contains the points (as polygons). arcpy.management.Project("cattle-map-Polygon Group/C1E-64-B3", "CattlePolygons", 4326) Now we should probably do a little bit of cleanup: Every polygon appears twice in the featureclass (some remnant from converting from pdf to dxf), and the feature class includes the polygons from Hawaii and Alaska, which are now completely false. So we delete those polygons and then delete identical features: arcpy.management.DeleteIdentical("CattlePolygons", ["Shape"]) That tool is actually not licensed for me and it would take too long to change my license right now, so I'll do it in the next step... So now, everything that's left to do is to create points from the polygons: # create the point feature class
arcpy.management.CreateFeatureclass("", "CattlePoints", "POINT", spatial_reference=arcpy.SpatialReference(4326))
# for each polygon, insert its centroid into the point fc, if it isn't already there
existing_coordinates = []
with arcpy.da.InsertCursor("CattlePoints", ["SHAPE@"]) as i_cursor:
with arcpy.da.SearchCursor("CattlePolygons", ["SHAPE@"]) as s_cursor:
for polygon, in s_cursor:
point = polygon.centroid
coordinates = [point.X, point.Y]
if coordinates in existing_coordinates:
continue
existing_coordinates.append(coordinates)
i_cursor.insertRow([point]) I'll attach the resulting shapefile to this post. This only includes the points for the continental USA. If you need Hawaii and Alaska, you'll have to ask for the data or do it yourself. Just start with georeferenceing the dxf to the respective state.
... View more
11-21-2022
06:19 AM
|
2
|
1
|
4979
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|