Sunday, 1 November 2015

Is it possible to create a new service definition file from an existing ArcGIS service?


Is it possible to create a new service definition file from an existing ArcGIS service?


I have a python script that updates data on a daily basis. I have figured out how to restart/overwrite my existing service so that it will represent the change in the data. However doing so uses the default settings for the new service.


If possible, I would like to create a new service definition file from an existing service so that I do not have to go back manually and change the following parameters and capabilities:


Max # of Records Returned by Server, Lock Database, Max # of instances per machine,


Any advice would be great. Thanks


Here is the solution:


    # Deserialize response into Python object
dataObj = json.loads(data)

httpConn.close()

# Edit desired properties of the service
dataObj["minInstancesPerNode"] = 1
dataObj["maxInstancesPerNode"] = 10

newdict = dataObj["properties"]
newdict["maxRecordCount"] = 5000

# Serialize back into JSON

updatedSvcJson = json.dumps(dataObj)

Answer



You have several options:




  1. Go to the \%server%\arcgisserver\directories\arcgissystem\arcgisinput\%ServiceName%.MapServer\extracted\v101 and open the .mxd document which will allow you to save a new .sd file for re-use.




  2. Use Python or any scripting language of your choice to modify properties of an existing service. This is done by using ArcGIS REST Administrator API. Here is the sample for modifying properties of an existing service. I use it almost daily and it is very easy to write a script altering properties as needed. This is much more efficient imo than creating a service again from .sd.





  3. Publish a service with the required properties directly set by using ArcGIS REST Administrator API and ArcPy. In this case, you will be able to specify the advanced settings in advance. Again, refer to the samples from 2. above to get started.




google earth engine - Exporting images in native CRS and resolution


When I use “Export.image.toDrive” command in Google Earth Engine it requests to define the scale and CRS of the raster. I did a search, but could not find clear solution for it.



Is there any possibility to keep native scale and CRS of the image while exporting it?



Answer



The scale and the CRS are optional when Exporting to Drive. By default, the CRS is the native one, and the resolution is 1000M per pixel. To set the native resolution:


var myScale = myImage.projection().nominalScale()


Delete points on a polygon using QGIS


I'm new at this, a novice at best. I'm using QGIS 1.7.3. I simply want to select a large number of points on a single polygon and delete them. Is this possible?




arcgis desktop - Time series animation problem


How to create time series animation with unequal time interval in the data in ArcGIS? for eg I have population data for the years 2013,2012,2010,2004,1990,1950,1900, so how can I create time series animation with this kind of unequal time interval?





qgis - Install qgis2web plugin



I would like to know how and where I can download qgis2web Plugin. I use QGIS with 2.10.1 version.




arcpy - Determining if Layer is Point using Python Toolbox?


I have been working on a Python toolbox which contains 6 parameters. I am a little lost on all of the different data types available in ArcMap (it seems like there's hundreds of them!). However, one of the input parameters has a file extension of .shp (shapefile). I have always used the GPFeatureLayer data type and it has always worked for everything else I hope to do with my tool, although I don't completely understand why. I have only been doing my testing with point shapefiles for the time being.


What I would ultimately hope to do is check if the user has entered a shapefile that is not a point (or a collection of points). If it is not a point, throw a warning to the user, but still allow them to use the tool. From what I understand, you can check the shape type by utilizing the Describe() class. However, when I attempt to pass my parameter into Describe (in order to return a Describe object), ArcMap throws an error:


enter image description here


Here is how I define the parameter I am focusing on:


def getParameterInfo(self):
"""Define parameter definitions"""


# First parameter = layer with customized features
param0 = arcpy.Parameter(
displayName = "Source layer with customized features",
name = "source",
datatype = "GPFeatureLayer",
parameterType = "Required",
direction = "Input")

And I was hoping to throw the warning in the updateParameters() method:


def updateParameters(self, parameters):

if parameters[2].value == True:
parameters[3].enabled = True
parameters[4].enabled = True
parameters[5].enabled = True

else:
parameters[3].enabled = False
parameters[4].enabled = False
parameters[5].enabled = False


describe = arcpy.Describe(parameters[0])
if describe.shapeType == 'Point':
arcpy.AddWarning('Warning: This is a point shapefile')

Any ideas as to why I am getting this error?


Am I using the correct data type?


I have tried using other data types for this parameter, such as DEFeatureClass, GPPoint, and DEShapefile, but I received the following error if I tried adding my shapefile in as my parameter:


enter image description here


The error was the same regardless of which of the three I used.





My issue with the Describe() class has been cleared up by adding the .value extension in my updateParameters() method:


def updateParameters(self, parameters):
describe = arcpy.Describe(parameters[0].value)

However, now when I attempt to use the setWarningMessage() function, I get no response from ArcMap. My updateParameters() consists of the following:


def updateParameters(self, parameters):
describe = arcpy.Describe(parameters[0].value)
#check = str(describe.shapeType)
if describe.shapeType == 'Point':
parameters[0].setWarningMessage('This is a point feature class')

else:
parameters[0].clearMessage()

if parameters[2].value == True:
parameters[3].enabled = True
parameters[4].enabled = True
parameters[5].enabled = True

else:
parameters[3].enabled = False

parameters[4].enabled = False
parameters[5].enabled = False

return

When I add a shapefile that I know in fact is a point, the tool does not output a warning. It simply accepts it without any feedback to the user.


Does it matter if the Describe.shapeType function has an output of Unicode?


I tested this through the ArcMap Python window with the following sequence of commands:


enter image description here


However, even if I try to convert the Describe.shapeType to a string, I still don't get a warning message. I've done the following tests:




  1. Rather than checking for: if describe.shapeType == 'Point', I tried to check for: if describe.shapeType == u'Point', which would force it to check for a Unicode data type.

  2. Converting the shapeType into a string via str(decribe.shapeType).

  3. Using the encode method to change the Unicode into a sequence of ASCII characters: describe.shapeType.encode('ascii', 'ignore').


Hence, I've hit a wall once again.



Answer



I think it may be as simple as changing this line:


describe = arcpy.Describe(parameters[0].value)


or maybe


describe = arcpy.Describe(parameters[0].valueAsText)

references - Learning resources for PyQGIS?




I'm looking for some resources for learning PyQGIS.


It would be interesting having a collection of books or websites that provide some practical examples for learning the syntax or accomplishing specific tasks.


Ideally, these resources should give a general guidance for both beginner and experienced users.



Where to find QGIS tutorials and web resources? is a very similar question, but it gives help for learning QGIS, and not specifically PyQGIS (in fact, it doesn't have the PyQGIS tag).


Any help?



Answer



The following resources give a general guidance for learning or using PyQGIS and generally assume a minimum proficiency of working with Python.







  • PyQGIS 3 API Documentation: official documentation of the Python API. Documentation for each major release since v3.0 as well as the nightly version is provided;





  • PyQGIS Developer Cookbook: written for QGIS 2.x it is gradually updated to 3.x. It still may be helpful as a tutorial and a reference guide and gives a good overview of the principal functionalities.







PyQGIS Documentation:




  • PyQGIS Developer Cookbook: official introduction to PyQGIS programming. It is intended to work both as a tutorial and a reference guide and gives a good overview of the principal functionalities;





  • PyQGIS API Documentation: inofficial documentation of the Python API by SourcePole. It provides a searchable interface, but was not updated since QGIS 2.8;




  • QGIS C++ API Documentation: official C++ API documentation. While describing the C++ API, it can be useful for pyqgis development.




Online books:




Tutorials / Blogs / Web resources:




  • Nathan Woodrow: a blog mostly about QGIS stuff that also treats specific topics about the using of PyQGIS. The author is one of the most active QGIS developers;




  • nyalldawson.net: a blog with several posts about the using of PyQGIS. The author is one of the most active QGIS developers;




  • "How To" in QGIS: the site provides some suggestions for solving problems using PyQGIS. When possible, these tips are offered through simple code samples. I'm the author of this blog;





  • QGIS Tutorials and Tips: a section of this blog provides a series of tutorials for learning PyQGIS scripting. The author is a very experienced GIS specialist;




  • Lutra Consulting: a list of posts, having the PyQGIS tag, that cover some topics about PyQGIS.




arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...