At v10 there is a very Arcpy way of getting the installation directory for ArcGIS Desktop. It's very easy and it goes as follows:
Now we want to see what software is installed on the machine:
You'll ge a list of software installed on the machine.
Happy Coding!
Friday, December 3, 2010
Thursday, October 28, 2010
Dynamic Label Tip
When working with data driven pages, you might want to put the adjacent grid cells on the page layout. What happens is the cell is empty? By default, the value "[EMPTY]" will appear, which is not very pleasing. To get around this issue, there is a property called emptystr. If you set the emptystr=" " you will see nothing instead of "[EMPTY]."
Code sample below:
Code sample below:
< dyn emptystr=" " property="PageNumber_E" type="page" >
Tuesday, October 26, 2010
Assigning Alias to Custom Toolboxes
I create lots of custom scripts and toolboxes to help out with various tasks, and I noticed the following message the other day when I exported a script from model builder to python:
# Warning: the toolbox toolbox.tbx DOES NOT have an alias.
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.toolname(...) with arcpy.toolname_ALIAS(...)
Basically, the system is asking for an Alias to provide an additional unique identifier because tools within the same toolbox cannot have the same name, but tools in other toolboxes can have the same name.
To define an alias, open ArcCatalog and right click on the tbx file. Select properties, you'll see this:
That easy!
Enjoy
# Warning: the toolbox toolbox.tbx DOES NOT have an alias.
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.toolname(...) with arcpy.toolname_ALIAS(...)
Basically, the system is asking for an Alias to provide an additional unique identifier because tools within the same toolbox cannot have the same name, but tools in other toolboxes can have the same name.
To define an alias, open ArcCatalog and right click on the tbx file. Select properties, you'll see this:
Enter in an alias and press ok.That easy!
Enjoy
Monday, October 11, 2010
Friday, October 8, 2010
Alternate Access Mapping for SharePoint
Alternate Access Mapping enables you to access your Sharepoint site via a typical URL like http://mysharepoint.com instead of hitting the server name at http://mysharepointserver. In combination with DNS A host entries you can also define URLs like http://mysite.mysharepoint.com even though your My Site web application is hosted on a different port.
Let's start:
Let's start:
- Go to Central Administration
- Click on the Operations Tab
- Click on Alternate Access Mappings under Global Configuration
- You should now see a list of your web applications, switch over to the one you want to map to the new URL by selecting it from the drop down on the right side.
- Click on Edit Public URLs and change the desired zone URL type to your new domain name. You can also change your internal URLs also by clicking Add Internal URLs.
- Now you’ll have to switch over to your DNS server.
- Within the DNS Management Console and Under Forward Look up Zones:
- Add a new Primary Zone with your new domain name.
- Add a new Host (A) to the records and point the IP Address to the SharePoint server.
Enjoy
Labels:
Sharepoint
SharePoint 2007 - Enable Anonymous Access
1). To enable anonymous on the IIS web site do the following:
You can confirm that anonymous access is enabled by going back into the IIS console and checking the Directory Security properties.
2). Enable anonymous access in the site.
A couple of notes about anonymous access:
- Launching Internet Information Services Manager from the Start -> Administration Tools menu
- Select the web site, right click and select Properties
- Click on the Directory Security tab
- Click on Edit in the Authentication and access control section
- First get to your portal. Then under “My Links” look for “Central Administration” and select it.
- In the Central Administration site select “Application Management” either in the Quick Launch or across the top tabs
- Select “Authentication Providers” in the “Application Security” section
- Click on the “Default” zone (or whatever zone you want to enable anonymous access for)
- Under “Anonymous Access” click the check box to enable it and click “Save”
You can confirm that anonymous access is enabled by going back into the IIS console and checking the Directory Security properties.
2). Enable anonymous access in the site.
- Return to your sites home page and navigate to the site settings page. In MOSS, this is under Site Actions – Site Settings – Modify All Site Settings. In WSS it’s under Site Actions – Site Settings.
- Under the “Users and Permissions” section click on “Advanced permissions”
- On the “Settings” drop down menu (on the toolbar) select “Anonymous Access”
- Select the option you want anonymous users to have (full access or documents and lists only)
A couple of notes about anonymous access:
- You will need to set up the 2nd part for all sites unless you have permission inheritance turned on
- If you don’t see the “Anonymous Access” menu option in the “Settings” menu, it might not be turned on in Central Admin/IIS. You can manually navigate to “_layouts/setanon.aspx” if you want, but the options will be grayed out if it hasn’t been enabled in IIS
- You must do both setups to enable anonymous access for users, one in IIS and the other in each site
Labels:
Sharepoint
Thursday, October 7, 2010
Searching Esri ArcObject Help With Google
Here is a great tip I've picked up over the last couple of months. When working with the online help system for ArcObjects, you can sometimes get tons of search results for unrelated topics. For example, say you search Point or Polygon, you will get about 10,000 results from the forums, other help topics. It's basicly information overload!
Let's say you need to search the .NET ArcObjects help, so to streamline the search process, you can utilize Google's search engine by doing the following:
Let's say you need to search the .NET ArcObjects help, so to streamline the search process, you can utilize Google's search engine by doing the following:
- In order for google to work, you need the site. For this example, we will use http://help.arcgis.com/en/sdk/10.0/arcobjects_net/ao_home.html. You can to remove the http:// and the ao_home.html for your site reference.
- The result should be this: help.arcgis.com/en/sdk/10.0/arcobjects_net
- With our site in hand, navigate to google (http://www.google.com/) and create a new search entry as follows: "site:help.arcgis.com/en/sdk/10.0/arcobjects_net TEST"
- Copy the resulting URL and ignore the search results
- Go to: http://www.microsoft.com/windows/ie/searchguide/en-en/default.mspx
- Paste the resulting Google Search URL into the URL box
- Give it a descriptive name. Ex: Search .NET ArcObjects
- Click install
Labels:
.Net,
ArcObjects
Tuesday, October 5, 2010
Counting Values Script - Finding Likely Voters
It's election time in the United States, and some of you might be helping out with campaigns. A colleague of mine who helps out with campaigns asked for my advice on how to make a quick utility to examine who voted in the last four general elections. From that information, he would categories likely, unlikely, very likely voters.
Of course I said use python. It's quick, easy, and reusable:
where the inputTable is the table which contains the data you wish to sum up, CountFields is a collection of field names (multi-value object), and VotedValues is a comma separated string (value1,value2, etc...) that represents the values of a voter voted.
Now that the script is created, you need to create the toolbox in ArcCatalog or ArcMap:
Enjoy and Happy GISing
Of course I said use python. It's quick, easy, and reusable:
####################
# Input Parameters #
####################
inputTable = arcpy.GetParameterAsText(0)
CountFields = arcpy.GetParameterAsText(1)
VotedValues = arcpy.GetParameterAsText(2)
###################
# Local Variables #
###################
ElectionCountFieldName= "ElectionCount"
###################
# Logic #
###################
fields = arcpy.ListFields(inputTable)
for field in fields:
if field.name == ElectionCountFieldName:
arcpy.DeleteField_management(inputTable, ElectionCountFieldName)
break
del fields
arcpy.AddField_management(inputTable, ElectionCountFieldName, "TEXT")
rows = arcpy.UpdateCursor(inputTable)
splitVal = VotedValues.split(',')
for row in rows:
count = 0
for f in CountFields:
if str(row.getValue(f)) in splitVal:
count = count + 1
row.setValue(ElectionCountFieldName,str(count))
rows.updateRow(row)
del row, rows
arcpy.SetParameterAsText(3, inputTable)
where the inputTable is the table which contains the data you wish to sum up, CountFields is a collection of field names (multi-value object), and VotedValues is a comma separated string (value1,value2, etc...) that represents the values of a voter voted.
Now that the script is created, you need to create the toolbox in ArcCatalog or ArcMap:
Parameter | Name | Setup |
1 | Input Table/FC | Type: Feature Class or Table |
2 | Fields | Type: Field, Obtained From: Parameter 1, MultiValue: Yes |
3 | Voted Values | Type: String |
4 | Return Table/FC | Type: Table/FC, Direction: Output |
Enjoy and Happy GISing
Labels:
Python
Friday, September 10, 2010
2010 Census TIGER/Line Shapefiles
I know everyone is as excited as I am the the first round of TIGER data from the 2010 census starts being released in December 2010 to February 2011.
For the complete schedule: check out this.
Enjoy
For the complete schedule: check out this.
Enjoy
Labels:
GIS Data
Wednesday, September 8, 2010
Working with Special Characters
Every once in awhile you need to work with the following characters in XAML:
Error 5 Entity references or sequences beginning with an ampersand ‘&’ must be terminated with a semicolon ‘;’.
Error 4 ‘"’ is an unexpected token. The expected token is ‘;’.
You can encode invalid characters for use in XAML by using the following encoding syntax:
- >
- <
- "
- &
Error 5 Entity references or sequences beginning with an ampersand ‘&’ must be terminated with a semicolon ‘;’.
Error 4 ‘"’ is an unexpected token. The expected token is ‘;’.
You can encode invalid characters for use in XAML by using the following encoding syntax:
Character |
Encoding |
< |
< |
> |
> |
& |
& |
“ |
" |
space |
  |
‘ |
' |
(numeric character mappings) |
&#[integer]; or &#x[hex]; |
(nonbreaking space) |
  (assuming UTF-8 encoding) |
Labels:
Silverlight,
Silverlight 4.0
Thursday, August 19, 2010
Wednesday, August 11, 2010
Creating Private Methods in Python
Python, as you may or may not know, is a fully object oriented language and with the newly created ArcPy module for ESRI's ArcGIS Suite, users should start creating programs following some sort of OO design.
One design pattern to follow is the singleton pattern, which can be found here.
Once you have started diving into the world of classes, name spaces, and methods, it's time to figure out how to make methods private. It's surprisingly simple to do this. To make something private in python, just put two underscores in front of your method. That's it, now only that class can access that method.
Here is a small example:
This class contains two functions. One that will make the self.foo text upper case, and the other lower case. The capital method has the two __ in front of the method, and should not be seen by the user, and lower() has no underscores that therefore is public. Using the idle's we can easily show that __capital cannot be used publicly by a user:
Enjoy
A
One design pattern to follow is the singleton pattern, which can be found here.
Once you have started diving into the world of classes, name spaces, and methods, it's time to figure out how to make methods private. It's surprisingly simple to do this. To make something private in python, just put two underscores in front of your method. That's it, now only that class can access that method.
Here is a small example:
This class contains two functions. One that will make the self.foo text upper case, and the other lower case. The capital method has the two __ in front of the method, and should not be seen by the user, and lower() has no underscores that therefore is public. Using the idle's we can easily show that __capital cannot be used publicly by a user:
Enjoy
A
Labels:
OOP,
Programming,
Python
Thursday, July 29, 2010
Developer Cheat Sheets
Tired of googling for answers, check out this site: http://devcheatsheet.com/
It has all kinds of programming reference sheets which are good for quick look ups about various concepts.
Enjoy
It has all kinds of programming reference sheets which are good for quick look ups about various concepts.
Enjoy
Labels:
Programming
Friday, July 23, 2010
PyDev and Installing New Libraries/Modules
If you use PyDev to create python scripts, and you add new libraries to your development system, you will need to update the interpreter.
To do this do the following:
1) Click on Project -> Properties
2) Select PyDev - Interpreter/ Grammar
3) Under the interpreter combo box, click on the text that says: "Click here to configure an interpreter not listed."
4) Press Apply -> It will take a couple of minutes to look through your PythonPaths -> Press Ok
5) Begin Coding
Enjoy
To do this do the following:
1) Click on Project -> Properties
2) Select PyDev - Interpreter/ Grammar
3) Under the interpreter combo box, click on the text that says: "Click here to configure an interpreter not listed."
4) Press Apply -> It will take a couple of minutes to look through your PythonPaths -> Press Ok
5) Begin Coding
Enjoy
MVVM for Silverlight
MV-VM is a design pattern for Silverlight and WPF. I have recently ventured into this domain, and I found a good resource to reference:
http://viewmodelsupport.codeplex.com/
Check it out and Post you own links in the comments to help other with MVVM design patterns!
Enjoy
http://viewmodelsupport.codeplex.com/
Check it out and Post you own links in the comments to help other with MVVM design patterns!
Enjoy
Labels:
Silverlight 4.0
Wednesday, July 21, 2010
More on Generating Excel and Word with Python
The best way to figure out what you want to do with excel and word in python is to look at the VBA object model. Find the information here:
VBA Samples: http://technet.microsoft.com/en-us/library/ee692929.aspx
Excel: http://msdn.microsoft.com/en-us/library/aa269683(v=office.10).aspx
Word: http://msdn.microsoft.com/en-us/library/aa279125(v=office.10).aspx
Enjoy
VBA Samples: http://technet.microsoft.com/en-us/library/ee692929.aspx
Excel: http://msdn.microsoft.com/en-us/library/aa269683(v=office.10).aspx
Word: http://msdn.microsoft.com/en-us/library/aa279125(v=office.10).aspx
Enjoy
Labels:
Python
Tuesday, July 20, 2010
MS Word and Python - Helpful links
Recently I was asked to develop a geoprocessing script that creates a MS Word Doc. Here were some links that helped me out:
http://www.blog.pythonlibrary.org/2010/07/16/python-and-microsoft-office-using-pywin32/
http://libjoe.blogspot.com/2009/07/embedding-images-in-word-pythoncvb.html
http://win32com.goermezer.de/content/category/7/86/192/
http://code.activestate.com/recipes/279003/
http://www.daniweb.com/forums/thread129924.html
This is for excel:
http://www.python-excel.org/
Enjoy Everyone!
http://www.blog.pythonlibrary.org/2010/07/16/python-and-microsoft-office-using-pywin32/
http://libjoe.blogspot.com/2009/07/embedding-images-in-word-pythoncvb.html
http://win32com.goermezer.de/content/category/7/86/192/
http://code.activestate.com/recipes/279003/
http://www.daniweb.com/forums/thread129924.html
This is for excel:
http://www.python-excel.org/
Enjoy Everyone!
Labels:
Python
Wednesday, July 7, 2010
Web ADFs Will be Deprecated
The future of the Web AdfDF has been written on the wall. It shall be put to rest after version 10 of ArcGIS Server. Also, many of the new features like time awareness and feature service usage will not be supported at 10.
Check it out here.
Check it out here.
Wednesday, June 23, 2010
Question for readers
I want to hear from you, leave a comment answering this question:
How do you envision GIS being used with SharePoint?
Thanks
How do you envision GIS being used with SharePoint?
Thanks
Labels:
SharePoint 2010
Thursday, June 10, 2010
Spatial Web Parts with Silverlight in SharePoint 2010
In SharePoint 2010 (SP2010) you can create a silverlight web part pretty easy by just creating a custom control, then deploy the XAP file to the clientbin folder. I should note that the pre-canned silverlight web part that I am using does not allow for DCOM bridges to be used, so to communicate between multiple silverlight web parts you would have to the Messaging API, which is quite easy, but that's for another day.
Getting Started, Open Visual Studios 2010, and create an empty SharePoint Project and a Silverlight Application. For the Silverlight Application project ensure that the "Host the Silverlight Application in the new Web Site" is unchecked.
Now we are cooking with fire, and we can create our Silverlight application. For this example, I will just add a map and one layer to the project.
The next step is to place the XAP file in a location that can be used by SharePoint. Right click on the Silverlight Application we just created and select Properties. Click on the build tab and change the output path to: "..\..\..\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin\". Remove the quotes when you put this into the Output Path.
Save and compile the project. If you get any errors, it's most likely you need to reference the proper ESRI silverlight libaries.
The next step is to configure the SharePoint Project. Add a new item to the SharePoint project and select Module. Double click on the Elements.xml file.
Configure the elements file to match the above image, you need to change the path of the Url to "_layouts/clientsbin/ XAPFILENAME.XAP" and change the Path from the textfile name to the XAP file name.
Click on the module and select the Project Output Refer -> Add a member -> Choose the Silverlight Application name -> in the Deployment Type Select ElementFile -> press OK
Select Build From main toolbar -> Configuration Manager -> Uncheck all the builds except for the SharePoint Project Name and make sure the SharePoint Project has deploy checked.
Save the Project and deploy to SharePoint.
Open your SharePoint site -> Edit Page -> Add Silverlight Web Part -> enter in the text box the following "_layouts/clientbin/XAPFILENAME.XAP". You should now see your web part.
Getting Started, Open Visual Studios 2010, and create an empty SharePoint Project and a Silverlight Application. For the Silverlight Application project ensure that the "Host the Silverlight Application in the new Web Site" is unchecked.
Now we are cooking with fire, and we can create our Silverlight application. For this example, I will just add a map and one layer to the project.
The next step is to place the XAP file in a location that can be used by SharePoint. Right click on the Silverlight Application we just created and select Properties. Click on the build tab and change the output path to: "..\..\..\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin\". Remove the quotes when you put this into the Output Path.
Save and compile the project. If you get any errors, it's most likely you need to reference the proper ESRI silverlight libaries.
The next step is to configure the SharePoint Project. Add a new item to the SharePoint project and select Module. Double click on the Elements.xml file.
Configure the elements file to match the above image, you need to change the path of the Url to "_layouts/clientsbin/ XAPFILENAME.XAP" and change the Path from the textfile name to the XAP file name.
Click on the module and select the Project Output Refer -> Add a member -> Choose the Silverlight Application name -> in the Deployment Type Select ElementFile -> press OK
Select Build From main toolbar -> Configuration Manager -> Uncheck all the builds except for the SharePoint Project Name and make sure the SharePoint Project has deploy checked.
Save the Project and deploy to SharePoint.
Open your SharePoint site -> Edit Page -> Add Silverlight Web Part -> enter in the text box the following "_layouts/clientbin/XAPFILENAME.XAP". You should now see your web part.
Tuesday, May 11, 2010
Serialization With Silverlight
Say you want to serialize an object using silverlight, well you can't use the binaryformater() like in windows forms development, so what to do. Silverlight has a the DataContractSerializer class which "Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract." So this means that you are passing XML string data.
From the windows help: "Use the DataContractSerializer class to serialize and deserialize instances of a type into an XML stream or document. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in an XML document for later retrieval, or in an XML stream for immediate transport."
Here is my code:
Enjoy
From the windows help: "Use the DataContractSerializer class to serialize and deserialize instances of a type into an XML stream or document. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in an XML document for later retrieval, or in an XML stream for immediate transport."
Here is my code:
Enjoy
Labels:
Silverlight 4.0
Getting Started with Geoprocessing and ArcObjects in .NET
Not a programmer and don't know where to start?
Here is a great "how to get started" article for from ArcUser magazine.
Enjoy
Here is a great "how to get started" article for from ArcUser magazine.
Enjoy
Labels:
.Net
Thursday, April 29, 2010
The Joys of Installs
Today I decided to roll up my sleeves and install SharePoint 2010 beta.
First I decided that I wanted to use Windows 7 64-bit, which was a mistake. All the documents point to the fact that you can do an install on win7-64bit, but you can't. You need to alter the config.xml file.
So I alter everything, and now the setup likes it, yippee, and get the 300 prerequisites installed. (See: http://blogs.msdn.com/opal/archive/2009/10/25/sharepoint-2010-pre-requisites-download-links.aspx for pre-reqs) Now I'm ready to install SP 2010 and configure it. Oh wait, I'm not... error after error, and most of the answers are found here, www.google.com because Microsoft's help is crap.
Getting sick of the errors, and a glutton for punishment, I decided to format my HD and install Windows 2008, which is the desired OS for sharepoint.
Installation was long, but it went like a breeze, and I did have one funny moment when this appeared:
Take a close look, it says the file should be less than 1 mb, but it was well over 6 mb and growing. Thanks Microsoft.
Now on to installing Silverlight and the MapIt Demo.
First I decided that I wanted to use Windows 7 64-bit, which was a mistake. All the documents point to the fact that you can do an install on win7-64bit, but you can't. You need to alter the config.xml file.
So I alter everything, and now the setup likes it, yippee, and get the 300 prerequisites installed. (See: http://blogs.msdn.com/opal/archive/2009/10/25/sharepoint-2010-pre-requisites-download-links.aspx for pre-reqs) Now I'm ready to install SP 2010 and configure it. Oh wait, I'm not... error after error, and most of the answers are found here, www.google.com because Microsoft's help is crap.
Getting sick of the errors, and a glutton for punishment, I decided to format my HD and install Windows 2008, which is the desired OS for sharepoint.
Installation was long, but it went like a breeze, and I did have one funny moment when this appeared:
Now on to installing Silverlight and the MapIt Demo.
Labels:
Sharepoint,
Windows 2008
Tuesday, April 27, 2010
Google Charts
Google charts is a great/free resource for doing charting. Many organizations have restrictions on what software you can install, but with google charts no software is needed, just an internet connection. See this link.
Here is a simple example:
To get this image, all you have to do is reference this url: http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
You can simply couple this with python using the webbrowser library. To open the image in a web browser via python try this:
webbrowser.open(url)
Here is a simple example:
To get this image, all you have to do is reference this url: http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
You can simply couple this with python using the webbrowser library. To open the image in a web browser via python try this:
import webbrowser
url = http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
webbrowser.open(url)
Thursday, April 15, 2010
Don't Buy This
This is the worst children's toy ever. I hate cubicles because they prevent creativity. I would never buy my child this.
Here is more information.
Monday, April 12, 2010
Working with ArcPy
If you haven't heard, ArcPy is the new geoprocessing module that will be out with version 10 of ArcGIS Desktop.
ArcPy has some great new features, especially if you use eclipse to program in python. It is intellasense capable, which makes programming nice and easy. It is also a well organized set of functions with libraries, class, functions, etc... Basically it follows OOP patterns.
What I don't like, is the case sensitivity. This can get annoying, since I'm a lazy programmer. Really, who has time to be pushing that shift key and another letter on the key board?
I think the future looks bright for ArcPy, but only time will tell.
ArcPy has some great new features, especially if you use eclipse to program in python. It is intellasense capable, which makes programming nice and easy. It is also a well organized set of functions with libraries, class, functions, etc... Basically it follows OOP patterns.
What I don't like, is the case sensitivity. This can get annoying, since I'm a lazy programmer. Really, who has time to be pushing that shift key and another letter on the key board?
I think the future looks bright for ArcPy, but only time will tell.
Thursday, March 25, 2010
Visual Studios 2010 Release Date
The release date for Visual Studios 2010 is set for:
Monday, 12 April 2010
Mark it down
Monday, 12 April 2010
Mark it down
Labels:
.Net
Tuesday, March 23, 2010
Reinstalling VS 2008
Here's what I think of the stupid people images on the VS 2008 install:
I put the I love Microsoft because apparently it makes some people warm and fuzzy. Maybe they should improve the installer so it doesn't take 1/2 your work day.
Labels:
.Net
Using Kernel Density
Has anyone ever been able to get the kernel density function to work in a python script? It appears that the function does not honor the inputs, but I could be mistaken. Post some code if you got it working.
The script I'm using is published to ArcGIS Server, and the kernel density if performed from the ArcToolbox, it returns the proper image, while the python call returns a black or blank tile, depending on how ArcGIS Server want to behave that minute.
It's very frustrating because no errors are returned, and both the script and arctoolbox function work in desktop.
The script I'm using is published to ArcGIS Server, and the kernel density if performed from the ArcToolbox, it returns the proper image, while the python call returns a black or blank tile, depending on how ArcGIS Server want to behave that minute.
It's very frustrating because no errors are returned, and both the script and arctoolbox function work in desktop.
Wednesday, March 10, 2010
ArcGIS Explorer 1200 Released
A new version of ArcGIS Explorer (build 1200) is now available for download at:
http://www.esri.com/software/arcgis/explorer
http://resources.esri.com/arcgisexplorer
If you've not installed ArcGIS Explorer before, you can run the system check utility or review the platform requirements before you install. If you are already using ArcGIS Explorer on the same machine as ArcGIS Desktop, please note that the uninstall may take a few minutes...
Find the Official Announcement Here.
http://www.esri.com/software/arcgis/explorer
http://resources.esri.com/arcgisexplorer
If you've not installed ArcGIS Explorer before, you can run the system check utility or review the platform requirements before you install. If you are already using ArcGIS Explorer on the same machine as ArcGIS Desktop, please note that the uninstall may take a few minutes...
Find the Official Announcement Here.
Labels:
AGX1200
Friday, March 5, 2010
What the Heck is *args and **kwargs in my Function?
Take the following code example:
Let's call this function:
c.method3()
You'll notice that method3() will not be called because our super() is passing in a variable gp, and it is expecting all classes to accept one parameter in the __init__().
A small change to your program can be done to fix this problem by using *args and **kwargs.
The *args is used to pass a variable-length argument list, and the **kwargs form is used to pass a dictionary object of variable length.
c = Child()
c.Method1()
c.method2()c.method3()
You'll notice that method3() will not be called because our super() is passing in a variable gp, and it is expecting all classes to accept one parameter in the __init__().
A small change to your program can be done to fix this problem by using *args and **kwargs.
The *args is used to pass a variable-length argument list, and the **kwargs form is used to pass a dictionary object of variable length.
By modifying the class SomeClass' __init__() by adding *args and **kwargs, you can now have functions that doesn't need variables to just ignore the variables being passed for this function.
In the other Classes you should use either the *args or **kwargs for your parameters too. You can check if the len() of the list is correct, and if so, assign the values.
Thursday, March 4, 2010
Singleton Exmple
Building off of my last post, I am going to post a singleton example that performs geographic functions.
1) Create your Singleton classHere there is a singleton class that will return the same instance of the object every time a specific class is called.
2) Create your class and have it inherit from Singleton
Now to use this, simply create a __main__ declaration, and create the object GeometryObject()
This gives you the output of:
1) Create your Singleton classHere there is a singleton class that will return the same instance of the object every time a specific class is called.
2) Create your class and have it inherit from Singleton
Now to use this, simply create a __main__ declaration, and create the object GeometryObject()
This gives you the output of:
Notice that GO and GO2 are the same exact object. This is what you want if you create a Singleton, only one instance of the object.
Singleton Pattern Design for Python
There are three categoris of OO Patterns:
A Singleton is a way to ensure that you cannot create more than one instance of a class. A class attribute could be used to check the number of instantiations of the class.
The singleton patter requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected.
As a note: "The singleton pattern must be carefully constructed in multi-threaded applications. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one. If the programming language has concurrent processing capabilities the method should be constructed to execute as a mutually exclusive operation." ~From http://en.wikipedia.org/wiki/Singleton_pattern
Here are two examples of Singleton Patterns:
This will produce an output of:
Here is a second singleton implementation that returns the same instance of the singleton instead of throwing an error:
I would recommend starting to use Design Patterns in your ArcGIS Python code. With the coming of 10, it will be more important than ever to have code that conforms to standard coding practices.
The goal of any OO programming is the following:
- Creational - patterns that can be used to create objects
- Structural - patterns that are used to combine object and classes in order to build structured objects
- Behavioral - patterns that can be used to build computation and control the flow of data
A Singleton is a way to ensure that you cannot create more than one instance of a class. A class attribute could be used to check the number of instantiations of the class.
The singleton patter requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected.
As a note: "The singleton pattern must be carefully constructed in multi-threaded applications. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one. If the programming language has concurrent processing capabilities the method should be constructed to execute as a mutually exclusive operation." ~From http://en.wikipedia.org/wiki/Singleton_pattern
Here are two examples of Singleton Patterns:
This will produce an output of:
Here is a second singleton implementation that returns the same instance of the singleton instead of throwing an error:
I would recommend starting to use Design Patterns in your ArcGIS Python code. With the coming of 10, it will be more important than ever to have code that conforms to standard coding practices.
The goal of any OO programming is the following:
- Genericity - is a technique to define parameters for a module exactly as you define parameters for a function thus making the module more general
- Flexibility - very difficult to achieve, but functions should be written as general as possible to allow for multiple data types
- Inheritance - is the ability in OO Programming to derive a class from another, either by extending it or specialize it
- Overloading - refers to the possibility for an operator or method to behave differently according to the actual data types of their arguments
- Polymorphism - is the possibility for something to have several forms.
Monday, February 22, 2010
Fun With Adding Fields
A common process that can be done multiple times during analysis is creating new feature classes. To strealine this process, I have developed a class that can create a feature class and add fields.
1). Create a python class and create the following Enum Classes
code>
class SomeClass:
def __init__(self, GP):
self.GP = GP
class FeatureType:
POLYGON = "POLYGON"
POLYLINE = "POLYLINE"
POINT = "POINT"
class AddFieldTypesEnum:
TEXT = "TEXT"
FLOAT = "FLOAT"
DOUBLE = "DOUBLE"
SHORT = "SHORT"
LONG = "LONG"
DATE = "DATE"
BLOB = "BLOB"
RASTER = "RASTER"
2). Add the following code below the class AddFieldTypesEnum
The class is ready to use
Here is a simple example:
1). Create a python class and create the following Enum Classes
code>
class SomeClass:
def __init__(self, GP):
self.GP = GP
class FeatureType:
POLYGON = "POLYGON"
POLYLINE = "POLYLINE"
POINT = "POINT"
class AddFieldTypesEnum:
TEXT = "TEXT"
FLOAT = "FLOAT"
DOUBLE = "DOUBLE"
SHORT = "SHORT"
LONG = "LONG"
DATE = "DATE"
BLOB = "BLOB"
RASTER = "RASTER"
2). Add the following code below the class AddFieldTypesEnum
def CreateFeatureClass(self, workspace="in_memory", fileName="temp", FeatureType=FeatureType.POLYGON, SpatialReference="", Fields=[],overwrite=True):
gp = self.GP
if gp.exists(workspace + os.sep + fileName) == True and overwrite == True:
if gp.overwriteoutput != 1:
gp.overwriteoutput = 1
#gp.delete(workspace + os.sep + fileName)
elif gp.exists(workspace + os.sep + fileName) == True and overwrite == False:
gp.adderror("Feature with name: " + fileName + " alread exists")
if SpatialReference == "":
desc = gp.describe(self.FC)
SpatialReference = desc.SpatialReference
gp.createfeatureclass(workspace, fileName, FeatureType, "","","",SpatialReference)
if len(Fields) > 0:
for field in Fields:
gp.addfield(workspace + os.sep + fileName, field[0], str(field[1]))
return workspace + os.sep + fileName
The class is ready to use
Here is a simple example:
import Arcgisscripting as Arc
gp = Arc.create(9.3)
myClass = SomeClass(gp)
myClass.CreateFeatureClass()
print 'dah da'
Tuesday, January 19, 2010
Graphing in python
Ever want to graph your results and you don't want to use the Google API or some other API like that, well along comes MatPlotLib.
Before I continue, make sure you have the ESRI media just in case your geo-statistics fails because numpy 1.3.0 and above are not supported officially be ESRI.
You'll need 3 things:
Python - v2.5.4
Matplotlib -v0.99.1
numpy - v1.3.0
You can install each version over top the older versions, so there is no need to uninstall anything.
Once setup, you can now create graphs in python to compliment your geoprocessing data.
There are great examples of how to use Matplotlib on the website. For example, you can do histograms, box plots, etc.. Also, you can include graph items like legends.
Happy Coding
~A
Before I continue, make sure you have the ESRI media just in case your geo-statistics fails because numpy 1.3.0 and above are not supported officially be ESRI.
You'll need 3 things:
Python - v2.5.4
Matplotlib -v0.99.1
numpy - v1.3.0
You can install each version over top the older versions, so there is no need to uninstall anything.
Once setup, you can now create graphs in python to compliment your geoprocessing data.
There are great examples of how to use Matplotlib on the website. For example, you can do histograms, box plots, etc.. Also, you can include graph items like legends.
Happy Coding
~A
Wednesday, January 13, 2010
ArcGIS 9.4 changed to ArcGIS 10.0
ESRI announced today that the next release will change from 9.4 to 10. You can here the official announcement here. Enjoy
Labels:
ArcGIS 10,
ArcGIS 9.4
Monday, January 11, 2010
FDO Error Guide for ArcSDE
Sometimes you want to know more about an SDE error, and here is a guide to help you. Click this link to go to the ESRI FDO user guide.
Subscribe to:
Posts (Atom)