Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

Sample for publishing a geodatabase? #159

Closed mshihadeh closed 8 years ago

mshihadeh commented 8 years ago

I am new to Python, and am trying to write a script that I can add to my task scheduler to zip, upload, and publish a geodatabase to AGOL. In the examples here, all items have been added using the simple addItem, but my geodatabase exceeds the maximum size for this method. It is likely that I will need to use uploadByParts, but I am having a bit of trouble figuring out how to go about this (again, very new to Python). I was hoping someone could add a sample of this code for me. It would be much, much appreciated!

achapkowski commented 8 years ago

Use the add item function and set multipart to true

mshihadeh commented 8 years ago

Thanks, I've set multipart to true and am successfully uploading the geodatabase, so thank you for that. However, I am now having a problem getting the proper publish parameters. Analyze and analyze parameters is set up nicely to return the base parameters for a csv that can be passed directly to publish, but I can't seem to find anything to do the same with a file geodatabase. I tried using the csv analysis and force a fileGeodatabase fileType, but not surprisingly, it does not work. Any suggestions?

achapkowski commented 8 years ago

You don't use analyze, that is only for CSV.

For publishing FGDB, use the PublishFGDBParameter class.

mshihadeh commented 8 years ago

I realize analyze is for CSV files, but there is nothing comparable to this for geodatabases, as I mentioned. Analyze retrieves the publish parameters for a CSV file to be passed to PublishCSVParameters, most importantly having layerInfo set up correctly. Similarly, I need to retrieve this information for the geodatabase, so I can pass layerInfo and other parameters to PublishGDBParameters, but I do not see a method for retrieving this data so that it is in the proper format. Am I missing something?

achapkowski commented 8 years ago

Sample below.

import arcrest    
if __name__ == "__main__":
    username = ""
    password = ""
    sh = arcrest.security.AGOLTokenSecurityHandler(username, password)
    admin = arcrest.manageorg.Administration(securityHandler=sh)
    content = admin.content
    user = content.users.user()

    ip = arcrest.manageorg.ItemParameter()
    ip.title = "gridtest234wefrgts324e8r09"
    ip.type = "File Geodatabase"
    ip.tags = "fgdb,code"
    ip.description = "fgdb item"
    ip.snippet = ip.description
    ip.archiveSelect = "filegeodatabase"
    item = user.addItem(itemParameters=ip,
                        filePath=r"C:\temp\grid.gdb.zip")

    ppFGDB = arcrest.manageorg.PublishFGDBParameter(name="fgdbcode",
                                                    layerInfo={"capabilities":"Query"},
                                                   description="item.description",
                                                   copyrightText="NA")
    res = user.publishItem(fileType="filegeodatabase", publishParameters=ppFGDB,
                           itemId=item.id, wait=True)