POST
|
The solution is to provide actual date in UTC import datetime
from arcgis.gis import GIS
from arcgis.features import Table
g = GIS(username="my_user_name", password="my_secret")
pit = g.content.get('my_published_csv_item_id')
t = Table.fromitem(item=pit)
t.delete_features(where="my_datet_time_column < '{}'".format((datetime.datetime.utcnow() - datetime.timedelta(seconds=3600)).strftime("%Y-%m-%d %H:%M:%S")))
... View more
01-09-2020
03:21 AM
|
1
|
0
|
1044
|
POST
|
Many thanks Joshua, I can delete by oids (and this is my workaround at the moment - I run table.query with time condition and then collect oids and delete with another call) However since calls to arcgis are very expensive in terms of time I'd love to save one call if possible and run table.delete_features with query...
... View more
01-07-2020
08:27 AM
|
0
|
0
|
1044
|
POST
|
Thank you Joshua, I was thinking about edit_features, I'll give it a go. Taking advantage of opportunity (please let me know if you'd prefer me to open new question) - I try to run something like this: # below returns response suggesting query is correct
table.validate_sql(sql="my_timestamp_column < TIMESTAMP '2019-01-06 11:00:00'")
# below throws exception
table.delete_features(where="my_timestamp_column < TIMESTAMP '2019-01-06 11:00:00'")
Line 5 fails with exception: Traceback (most recent call last):
File "harvester/test/simulate_entry_point.py", line 40, in <module>
route_event(
File "/lib/python3.8/site-packages/arcgis/features/layer.py", line 1446, in delete_features
return self._con.post(path=delete_url, postdata=params, token=self._token)
File "/lib/python3.8/site-packages/arcgis/_impl/connection.py", line 1183, in post
self._handle_json_error(resp_json['error'], errorcode)
File "/lib/python3.8/site-packages/arcgis/_impl/connection.py", line 1204, in _handle_json_error
raise RuntimeError(errormessage)
RuntimeError:
Unable to delete features.
(Error Code: 400) There is only 40 items meeting criteria so should not be hitting any limits. I think this might be due to open-ended nature of the query (although I'd like arcgis to delete all features meeting criteria, I have seen posts here where people had to run multiple queries with bundles of ~2000 items).
... View more
01-06-2020
10:05 PM
|
0
|
3
|
1128
|
POST
|
Hi Joshua, Indeed, I have put myself in wrong way. I meant that I need `FeatureLayer` so I can call append. If you look at my recent reply you will notice that indeed I'm able to call `append`. The problem I'm left with is if it's possible to use `append` without having to create item with new data. Many thanks,
... View more
01-03-2020
11:50 AM
|
0
|
0
|
2736
|
POST
|
Hi, can you help me understand if it's possible to append data without creating new item? In your example you are appending getclippedSoilsSHPItemID to item with ID:" 60820364b71743c49822a60da1e85492 ". Do you think it's possible to append CSV that I have directly on my hdd? As far as I can see I need to create this interim item and upload CSV there, and only then I can use that item to append to another item.
... View more
01-03-2020
05:57 AM
|
0
|
1
|
2817
|
POST
|
I managed to get ***sort-of*** what I need... however I'm still trying to understand how to make `arcgis` to upload some data directly from my hard drive rather than from another item. Anyways here is the code: import arcgis
import json
from arcgis.gis import GIS
g = GIS(username="my_uname", password="my_pwd")
item_properties_1={"type": "CSV", "title": "test_feature_collection_01"}
it_1 = g.content.add(item_properties=item_properties_1, data="/tmp/my_data.csv")
pit_1 = it_1.publish()
table = arcgis.features.Table.fromitem(item=pit_1)
# Now we want to throw some extra data, do we have to create another item to do that??
item_properties_2={"type": "CSV", "title": "test_feature_collection_02"}
it_2 = g.content.add(item_properties=item_properties_2, data="/tmp/more_data.csv")
source_info = g.content.analyze(file_path='/tmp/more_data.csv', file_type='csv', location_type='none')
# Data from `it_2` appears to be appended to `table` container (which is published item, not item itself)
table.append(item_id=it_2.id, upload_format='csv', source_info=source_info["publishParameters"], upsert=False)
So to append some data to existing item I have to create new item... So the question now is how to append with data I have at hand without creating new item?
... View more
01-03-2020
05:30 AM
|
0
|
0
|
2736
|
POST
|
I'm trying to create new instance of [arcgis.features.FeatureLayer](https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#featurelayer) using python arcgis package. I find it impossible, I'm traversing through [documentation](https://developers.arcgis.com/python/api-reference) and [examples](https://developers.arcgis.com/python/guide/appending-features/#Append-attribute-values-from-the-csv-item-into-target-feature-layer-attribute-field) trying different things and I find myself going round in circles and slowly I start pulling my hear out... This is what I have: import arcgis
import json
from arcgis.gis import GIS
g = GIS(username="my_uname", password="my_pwd")
prop = arcgis.features.FeatureCollection(dictdata={'attributes': {'foo': 'bar', 'lorem': 'ipsum'}})
prop_json=json.dumps({"featureCollection": {"layers": [dict(prop.properties)]}})
item_properties={"type": "Feature Collection", "title": "test_feature_collection_01", "text": prop_json}
it = g.content.add(item_properties=item_properties)
At this point - I can't understand why `it.layers` yields empty results. I believe `item_properties` is malformed resulting in `arcgis` ignoring my layers definition... but I have nowhere to check what it should look like. I figured I'd like to use something from `arcgis` to generate layer definition for me rather than to handcraft JSON myself so it's future-proof. What I want to do with that item later is this: lr = arcgis.features.FeatureLayer.fromitem(item=it)
This fails with `TypeError: item must be a type of service, not Feature Collection` So I figured I could publish item and use it here. pit = it.publish()
lr = arcgis.features.FeatureLayer.fromitem(item=pit)
I need `FeatureLayer` to be able to call `append` (so I can just throw extra data each time I have anything new I want to push) But to my surprise I cannot even publish the item and I'm getting `Exception: Job failed.` (to my bigger surprise item actually gets published as I can see it through content manager website) I also tried creating "CSV" item type: import arcgis
import json
from arcgis.gis import GIS
g = GIS(username="my_uname", password="my_pwd")
item_properties={"type": "CSV", "title": "test_feature_collection_01"}
it = g.content.add(item_properties=item_properties, data="/tmp/foo.csv")
pit = it.publish()
lr = arcgis.features.FeatureLayer.fromitem(item=pit)
however this results in layer-less item, which results in unhandled exception `IndexError: list index out of range` (because method `arcgis` tries to get to layers which is empty...) Please help...
... View more
01-03-2020
04:07 AM
|
0
|
4
|
2987
|
Title | Kudos | Posted |
---|---|---|
1 | 01-09-2020 03:21 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|