Hi,
I want to generate a geodatabase which contain all feature layers data so that I can use that database when there is no internet connection but I do not want to give an option to user to select area of interest. All feature layer data should be download automatically in background.
Thanks,
Kamal
Hi Kamal.
For each layer you specify in the AGSGenerateGeodatabaseParameters object that you pass to generateJobWithParameters(), you can specify an AGSGenerateLayerOption object. That object has a useGeometry property that you can set to false.
Below is the code which I am using to download feature layer. Right now I am getting exception "
Geometry cannot be null in generate geodatabase parameters.
". Actually I want to download all feature layer data automatically in background without user selecting area.
private let FEATURE_SERVICE_URL = NSURL(string: "https://services7.arcgis.com/JRY73mi2cJ1KeR7T/arcgis/rest/services/NewYorkHospitalLayer/FeatureServer/0")!
private var syncTask:AGSGeodatabaseSyncTask!
private var generateJob:AGSGenerateGeodatabaseJob!
private var generatedGeodatabase:AGSGeodatabase!
override func viewDidLoad() {
super.viewDidLoad()
self.map = AGSMap(basemap: AGSBasemap.streetsBasemap())
self.syncTask = AGSGeodatabaseSyncTask(URL: self.FEATURE_SERVICE_URL)
self.addFeatureLayers()
self.mapView.map = self.map
self.generateGeodatabase()
}
func addFeatureLayers() {
self.syncTask.loadWithCompletion { [weak self] (error) -> Void in
if let error = error {
print("Could not load feature service \(error)")
} else {
guard let weakSelf = self else {
return
for (index, layerInfo) in weakSelf.syncTask.featureServiceInfo!.layerInfos.enumerate().reverse() {
//For each layer in the serice, add a layer to the map
let layerURL = weakSelf.FEATURE_SERVICE_URL.URLByAppendingPathComponent(String(index))
let featureTable = AGSServiceFeatureTable(URL:layerURL!)
let featureLayer = AGSFeatureLayer(featureTable: featureTable)
featureLayer.name = layerInfo.name
featureLayer.opacity = 0.65
weakSelf.map.operationalLayers.addObject(featureLayer)
func generateGeodatabase() {
//create AGSGenerateLayerOption objects with selected layerIds
var layerOptions = [AGSGenerateLayerOption]()
let layerOption = AGSGenerateLayerOption(layerID: 0)
layerOption.useGeometry = false
layerOptions.append(layerOption)
//parameters
let params = AGSGenerateGeodatabaseParameters()
params.layerOptions = layerOptions
params.returnAttachments = true
params.attachmentSyncDirection = .Bidirectional
//name for the geodatabase
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let fullPath = "\(path)/\(dateFormatter.stringFromDate(NSDate())).geodatabase"
//create a generate job from the sync task
self.generateJob = self.syncTask.generateJobWithParameters(params, downloadFileURL: NSURL(string: fullPath)!)
//start the job
self.generateJob.startWithStatusHandler({ (status: AGSJobStatus) -> Void in
SVProgressHUD.showWithStatus(status.statusString(), maskType: .Gradient)
}) { [weak self] (object: AnyObject?, error: NSError?) -> Void in
SVProgressHUD.showErrorWithStatus(error.localizedDescription)
else {
SVProgressHUD.dismiss()
Print("Database generated successfully")
Hey Kamal,
Could you be a little more specific about what error you're getting?
Hi Nicholas,
I have updated my above code and I am getting below exception:
"Geometry cannot be null in generate geodatabase parameters."
Hi Kamal Mittal,
Maybe you can try this:
1. Based on our REST API, the Create Replica expects you to have geometry for sure:
ArcGIS REST API - Create Replica
2. Then we compare Runtime iOS SDK how to get Envelope. Then we will found this Class: ArcGIS Runtime SDK for iOS: AGSEnvelope Class Reference
3. Then we check generate Geodatabase Class, we saw this property: generateGeodatabaseExtent property
4. The rest we need to do is how to pass the AGSMapView's AGSEnvelope as a parameter to generateGeodatabaseExtent.
5. In AGSMapView Class Reference there is a visibleArea property. it is a AGSPolygon type, if you check this class, you will find there is a property called AGSEnvelope property in AGSPolygon
6. So technically you can use this line of code to assign the mapview extent as generate Geodatabase Extent:
generateGeodatabaseExtent <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>mapview<SPAN class="punctuation token">.</SPAN>visibleArea<SPAN class="punctuation token">.</SPAN>extent<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
http://resources.arcgis.com/en/help/arcgis-rest-api/#/Create_Replica/02r3000000rp000000/<strong></strong>
Hope this can help.
Nathan
Thanks for the additional info, Yue Wu.
Kamal Mittal To clarify, even though you need to provide a geometry to the AGSGenerateGeodatabaseParameters.extent property, setting the layer options as you did should override that and return all data.
Thanks Yue Wu for good explanation
Thanks Nicholas. Now I am able to get all layer data. There is one question for you. Can I include multiple feature layer url's data into same geodatabase and can use it when offline?.
My pleasure. As long as your feature layers are all come from the same feature service url, for example: Sync/WildfireSync (FeatureServer)
In this feature service, there are three feature layers, and you can use REST to create Replica and the download offline geodatabase can be use in offline mode as long as you setup all three layers to be downloaded.
Thanks for the reply.
Actually I have two different csv files which contain hospital and fire-hydrant data. I have uploaded them to ArcGIS online from the Add data option. Then it create two layers under content section and I have save them as a separate layer and publish it to ArcGIS online as feature layer so I get two different feature layer urls. So my question is can I publish these two layers as a single like Sync/WildfireSync from ArcGIS online?
Another thing is that I have one use case like "42 street is not accessible in newyork city". so how I show that usecase into Arcgis online basemap and publish it as a feature layer.
Last thing is that I am bit confuse about "REST to create Replica". How do I use that and how it can be helpful for me in IOS app.
Kamal Mittal
For hosted feature services, you need to use ArcMap to convert all your csv file by right click and choose Display XY Data. Here is a screenshot to illustrate this. For more information, please check our ArcMap doc Adding x,y coordinate data as a layer—Help | ArcGIS for Desktop
Then you can remove all your original .csv file and publish all the layer to your ArcGIS Online as hosted feature service. In this way, you will have one feature service that contains more than one layer. Here is a screenshot:
However for hosted feature service you do not have all the options to manually change prepare the data to use sync capabilities. Based on our doc Prepare data for offline use—Documentation | ArcGIS Enterprise
For the question about how REST create Replica works, I would recommend you first read our REST API doc first:
Create Replica - ArcGIS REST API
Then combine with our Runtime iOS SDK doc talks about Sync offline edits—ArcGIS Runtime SDK for iOS | ArcGIS for Developers
Hey Kamal,
Services with Multiple Layers
For creating multiple layers within one service from CSVs, as Yue mentions you currently have to use the Desktop tools. There are plans for an enhancement to enable this without Desktop tools but I don't have a timeline.
If you had Shapefiles instead of CSVs, you could combine the Shapefiles for each layer you want in a single folder, zip up that folder, and upload it. The zip file name will determine the Service name and each Shapefile will become a Layer within that Service (note: a "Shapefile" is made up many constituent parts - you would combine all those parts from all the Shapefiles in one flat folder, zip that up and upload it). I did that here (here is the REST endpoint).
Additionally, if you uploaded a File Geodatabase, that can be published as a Service with many Layers.
REST Actions to Create Replica
When you use the Runtime's AGSGeodatabaseSyncTask, it's using the REST Create Replica endpoint behind the scenes. Since you're using the Runtime you don't have to worry about this as it wraps all that up for you. Yue was just referring to that. I would add to Yue's response below that you don't need to dig into the REST APIs if you're OK with the Runtime SDK samples, but if you really want to get into the weeds, use the REST docs as reference.
Incidentally, you might find these two videos from the recent Developer Summit useful if you want to find out more about your options for working offline with the Runtime:
ArcGIS Runtime: Working with Maps Online and Offline
and
ArcGIS Runtime: Editing Your Data Online and Offline
Cheers,
Nick.
Thanks Nicholas for the video sharing and nice explanation. So we have to go with ArcMap or ArcGIS Pro for sharing multiple layers into one service url or to customize shapefile at own level?
Hi Kamal,
If the layers are based off CSVs, that's correct. If they're based off Shapefiles, my above description will get you a single Service with multiple Layers without using ArcMap or ArcGIS Pro.
But I'm not sure I understand "customize shapefile at own level". Perhaps you mean modifying shapefiles (changing data, adding or removing fields)?
If so, there is some limited stuff you can do in the browser. You can of course edit data and then you can export a FeatureLayer as a Shapefile using the Extract Data analysis tool. In fact, you might be able to use this workflow to upload multiple CSVs, extract them as multiple Shapefiles which you would then put into one folder locally before zipping and uploading that to create a single Service with multiple Layers. It's convoluted, but it should work.
You're also able to add and delete fields from a Feature Layer if you own it. This is done from the Table View in the ArcGIS Online Map Viewer.
In general, the Desktop tools significantly simplify many of these workflows. With Desktop you have good ways to script these workflows too with arcpy, although the new ArcGIS API for Python might be worth looking at for scripting some of this ArcGIS Online administration without a need for Desktop.
Hope that helps,
Nick
Thanks Nicholas for reply.
Currently I have one usecase. I want to indicate in map that "42nd street is not accessible in Newyork due to some emergency" so how I indicate that thing in map( should i indicate red line, area or polygon). Is this possible through arcgis online or I have to go with ArcGIS Pro or ArcMap to create shapefile of that thing and publish it to ArcGIS online? That is my main concern.
Absolutely.
So far we've been talking about taking existing data that you've obtained elsewhere as a CSV or Shapefile, but it sounds like you actually might simply want an empty FeatureService+Layer for redlining (or perhaps one for points, one for lines, and one for polygons). You can do this at the developer portal (log in with your org credentials). This will give you a lot of control over attribute names and types that go with each record. This DevLab explains how to do that: Create a new dataset
Once you create a layer through the developer portal you will see it in the main ArcGIS Online My Content browser.
But there is another option that might work for you. You can create a Feature Layer directly in the My Content browser from a Template. Select Create->Feature Layer, and look at the From Template tab. There's a Road Closures template that could work for you. Here's a blog post about that functionality. [Update: Here's the documentation on that too]
P.S. I recommend you take a look at all the DevLabs, but in particular the Data section sounds like it could be useful to you.
let localVectorTiledLayer = AGSArcGISVectorTiledLayer(name: "StreetMap_Day")self.map = AGSMap(basemap: AGSBasemap(baseLayer: localVectorTiledLayer))
let localVectorTiledLayer = AGSArcGISVectorTiledLayer(name: "StreetMap_Day")
self.map = AGSMap(basemap: AGSBasemap(baseLayer: localVectorTiledLayer))
I want to set initialViewPoint to NewYork City so how i get x,y and scale coordinates?
Any update on this?
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.