Package: earth-api
This python package is theArcGIS Earth Automation API. You can use this package to call some functions of ArcGIS Earth.Dependenciesurllib3 (1.15 or greater)six (1.10 or greater)certifipython-dateutilrequestsodInstallationThis package can be installed from the Python Package Index.$ pip install earth-apiUsageImportYou can use the following command to import the package.>>>fromearth_apiimportEarthAPIExamplesGet the current camera information>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,camera=earth.get_camera()>>>status_code200>>>camera{'position':{'x':-92.0,'y':41.0,'z':11000000.0,'spatial_reference':{'wkid':4326}},'heading':0.0,'tilt':0.0,'roll':0.0}Set the camera positionThe following codes are an example of the camera position.camera_dict={"position":{"x":113.59647525051167,"y":32.464715999412107,"z":2213290.0751730204,"spatialReference":{"wkid":4326},"heading":354.04823651174161,"tilt":19.96239543740441}}Then, you can set the camera position.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.set_camera(camera_dict)(200,{'result':'Success'})Set the flight targetThe following codes are an example of flight information.flight_dict={"camera":{"position":{"x":-92,"y":41,"z":11000000,"spatialReference":{"wkid":4326}},"heading":0.0,"tilt":0.099999999996554886},"duration":2}Then, you can set the flight.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.set_flight(flight_dict)(200,{'result':'Success'})Add a layerThe following codes are an example of layer information.layer_dict={"type":"MapService","URI":"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer","target":"OperationalLayers"}Then, you can add the layer to ArcGIS Earth.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,layer_infor=earth.add_layer(layer_dict)>>>status_code200>>>layer_infor{'id':'91713d46-45f3-4bc4-9c82-38384905f1e1','opacity':1.0,'displayName':'World_Imagery','isVisible':True,'classType':'Tiled_Layer','sourceURI':'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer','brightness':0.0,'contrast':0.0,'gamma':0.0,'lastTilingScheme':'WebMercator','surfacePlacement':'DrapedBillboarded','elevationOffset':0.0,'loadStatus':'Loaded'}Get the target layer informationYou can get the target layer information according to the layer id.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,layer_infor=earth.get_layer("91713d46-45f3-4bc4-9c82-38384905f1e1")>>>status_code200>>>layer_infor{'id':'91713d46-45f3-4bc4-9c82-38384905f1e1','opacity':1.0,'displayName':'World_Imagery','isVisible':True,'classType':'Tiled_Layer','sourceURI':'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer','brightness':0.0,'contrast':0.0,'gamma':0.0,'lastTilingScheme':'WebMercator','surfacePlacement':'DrapedBillboarded','elevationOffset':0.0,'loadStatus':'Loaded'}Remove the target layerYou can remove the target layer according to the layer id.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.remove_layer("91713d46-45f3-4bc4-9c82-38384905f1e1")(200,{'result':'Success'})Clear layersYou can clear all layers according to the following command.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.clear_layers()(200,{})Add the target graphicThe following codes are an example of a graphic.graphic_dict={"id":"point-picture-marker-graphic-js","geometry":{"type":"point","x":-100,"y":40},"symbol":{"type":"picture-marker","url":"https://static.arcgis.com/images/Symbols/Shapes/BlackStarLargeB.png","width":"64px","height":"64px","angle":0,"xoffset":"10px","yoffset":"10px"}}Then, you can add the graphic to ArcGIS Earth.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,graphic_infor=earth.add_graphic(graphic_dict)>>>status_code201>>>graphic_infor{'id':'point-picture-marker-graphic-js','geometry':{'x':-100,'y':40,'type':'point'},'symbol':{'angle':0,'height':48,'type':'picture-marker','url':'https://static.arcgis.com/images/Symbols/Shapes/BlackStarLargeB.png','width':48,'xoffset':7.5,'yoffset':7.5}}Get the target graphic informationYou can get the graphic information according to the graphic id.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,graphic_infor=earth.get_graphic('point-picture-marker-graphic-js')>>>status_code200>>>graphic_infor{'id':'point-picture-marker-graphic-js','geometry':{'x':-100,'y':40,'type':'point'},'symbol':{'angle':0,'contentType':'image/png','height':48,'type':'picture-marker','url':'https://static.arcgis.com/images/Symbols/Shapes/BlackStarLargeB.png','width':48,'xoffset':7.5,'yoffset':7.5}}Update the graphicYou can update the graphic according to the new graphic information.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.update_graphic(new_graphic_dict)(204,{})Remove the target graghicYou can remove the graphic according to the graphic id.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.remove_graphic("point-picture-marker-graphic-js")(204,{})Clear graghicsYou can clear graphics according to the following codes.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.clear_graphics()(204,{})Add a drawingThe following codes are a drawing example.drawing_dic={"id":"point graphic sample","title":"point graphic sample","geometry":{"x":-100,"y":40,"spatialReference":{"wkid":4326}},"symbol":{"type":"picture-marker","url":"https://static.arcgis.com/images/Symbols/Shapes/BlackStarLargeB.png","width":"30px","height":"30px"},"labelSymbol":{"type":"text","color":[100,100,100,255],"font":{"size":24}}}Then, you can add a drawing to ArcGIS Earth.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,drawing_infor=earth.add_drawing(drawing_dic)>>>status_code201>>>drawing_infor{'id':'point graphic sample','result':'Success'}Remove the target drawingYou can remove the target drawing according to the drawing id.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.remove_drawing('point graphic sample')(204,{})Clear drawingsYou can clear all drawings according to the following codes:>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.clear_drawings()(204,{})Get the current workspaceYou can get the current workspace of ArcGIS Earth.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>status_code,workspace_infor=earth.get_workspace()>>>status_code200>>>workspace_infor{'url':'http://localhost:8000/workspaces/f47b11cf-5dee-4f92-a528-6bc870b87874.zip','path':'C:\\Users\\username\\Documents\\ArcGISEarth\\automation\\workspaces\\f47b11cf-5dee-4f92-a528-6bc870b87874.zip'}Import the target workspaceYou can import the target workspace according to the workspace information.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>workspace_dict={"url":"http://localhost:6080/workspace.zip","path":"C:\\Users\\Administrator\\Desktop\\workspace.zip",}>>>earth.import_workspace(workspace_dict)(200,{'result':'Success'})Clear the current workspaceYou can clear the current workspace.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.clear_workspace()(200,{'result':'Success'})Get  the snapshotYou can get the current snapshot of ArcGIS Earth.>>>fromearth_apiimportEarthAPI>>>earth=EarthAPI()>>>earth.get_snapshot()(200,<urllib3.response.HTTPResponseobjectat0x0000027BB2FBB190>)