Home arrow GIS Data & Resources arrow Scripts and Code
GIS-Related Scripts and Programming Code

This section provides a venue for sharing GIS-related programming code and custom scripts in a variety of languages. Posts can be viewed by category or as a whole in blog format (below).

Category Links:

GIS Scripts and Code (Weblog format, All Posts):




VBA: Simple Geometry Output Example PDF Print E-mail

Written by Bert Granberg,

This ArcMap VBA code outputs a .csv ordered list of corner points from a polygon feature class of USGS Quadrangle boundaries.

Nothing fancy, just a quick and dirty example of how to access, quickly assess, and output the needed geometry values stored in a SHAPE type field. You could do the same thing in Python but using ArcObjects in VBA opens the doors to more powerful feature-level manipulation (looking at connectivity or proximity to other features for example) if you want to go beyond this simple analysis.

I doubt anyone will have a need to use this again for its specific purpose but its a good starting point for doing other, similar things.

Output will look something like this (in this example, my coords are in NAD83)

1, CO-OP SPRING, Q0214, 42112A5, 365680, 4664719, 376012, 4664530, 375768, 4650651, 365416, 4650840, 365680, 4664719

2, GROVER CANYON, Q0215, 42112A4, 376012, 4664530, 386345, 4664356, 386121, 4650477, 375768, 4650651, 376012, 4664530

.
.
.

1540, CHOCOLATE DROP, Q3832, 37110E3, 555153, 4164188, 566184, 4164269, 566295, 4150401, 555246, 4150320, 555153, 4164188

User Comments (1)
29, Jan. 2009
Last Updated ( 29, Jan. 2009 )
Read more...
 
Validate ASP.NET Membership username availability with client side AJAX sorta PDF Print E-mail

Written by Steve Gourley,


I've been watching some videos lately of some presentations in Canada about web 2.0 and effective form design. They spoke a lot about giving your application a personality as well as making your forms more conversational. Don't make them too long or people won't fill them out. Piece them small so they can gain momentum to finish the process. This could be a totally different post but since this is a GIS portal and I'm blogging about programming I'm already in left field but I'll get to my point.

When you have an application that requires a login, your audience needs to be able to choose a user name. One of the side comments of these presentations was that you shouldn't make a user fill out an entire registration form and then throw some error saying, "Your user name was taken. Fill out the entire form again and try another name." Your target audience will close the window and go about the rest of their day.

So what I went through today was using MS ajax toolkit's ValidatorCalloutExtender with an asp customValidator and some dojo to make an JSON GET request to a WCF service which can check the availability of the typed in username - before they submit the form! If the name is chosen the validator callout with display a message and subsequently block the posting of the data if they were to try to submit the page ignoring the callout.

Some things I noticed is that the customvalidator has to have enableClientScript = true. The ClientValidationFunction, your javascript function, takes a source and clientside_arguments parameter. Setting the clientside_arguments.IsValid = false will display the callout message. As a side note, the validatorCalloutExtender does not work with server side validation. One other hitch is that using the dojo.xhrGet function to initiate the server side code needs to be syncronous. Async calls result with... well, nothing. So I guess this isn't truely ajax since it's not asynchronous but... oh well. dojo.xhrGet is async by default so you need to add sync: true to your hash.

Here's the code to do what I accomplished.


<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="test"></asp:TextBox>

    <asp:CustomValidator ID="CV_username" runat="server" ErrorMessage="<b>Username already taken</b><br />Please choose another username"

        Display="None" SetFocusOnError="true" ValidateEmptyText="false" ValidationGroup="test"

        ClientValidationFunction="check" ControlToValidate="TextBox1" EnableClientScript="true" />

    <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="VCE_test" TargetControlID="CV_username"

        HighlightCssClass="validatorCalloutHighlight" Width="225px" BehaviorID="VCE_test" />

 

    <script type="text/javascript">        djConfig = { parseOnLoad: true }</script>

 

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.2"></script>

 

    <script language="javascript" type="text/javascript">

 

        function check(source, clientside_arguments) {

            var User = { 'username': clientside_arguments.Value, 'application': "/WRI" };

            var request = { 'User': dojo.toJson(User) };

 

            dojo.xhrGet({

                url: "http://agrc-sgourley2/WSUT/Validate.svc/CheckAvailability",

                handleAs: 'json',

                content: request,

                sync: true,

                load: function(result, ioArgs) {

                    console.log(result);

                    clientside_arguments.IsValid = result;

                },

                error: function(err) {

                    clientside_arguments.IsValid = false;

                }

            });

        }


Comment on this Article
22, Jan. 2009
Last Updated ( 22, Jan. 2009 )
 
ArcMap .CAL Script: Service Area Count From Intersecting Polygons PDF Print E-mail

Written by Bert Granberg,

BACKGROUND

A service area polygon is a polygon in which a particular service or service level is the same and whose external boundaries demarcates a change from one service situation to another.

This script was written for work with cell phone towers and sectors. A sector is the area served by a particular cell phone antenna and is defined by the tower location, height on antenna and the left and right directional azimuth of antenna. The goal was to calculate the level of service for all locations served by an array of cell phone
antennae in a given area.

To accomplish this, sector polygons were created and then these sector polygons were planarized (all overlaps were removed) to form service areas for the cell phone network. The goal of the script is to count the number of cell phone sectors that overlap a particular service area.

  • Note: To create the planar service area polygons you'll need before running the script, you'll need an ArcGIS ArcEditor or ArcINFO level license. I like to do this in arccatalog by putting the sector polygons into a geodatabase feature dataset and right clicking in the feature database and selecting New --> Polygon Feature Class from Lines.

This .cal script is for calculating the number of "customer" polygons (in our case these are the cell phone antenna sectors) in a given service area polygon. It produces a numeric count for the number of customer features in the specified customer layer that intersect the midpoint of the given polygon (see example depiction below).

 

TO USE: 

  • open the attribute for the planar service area polygons, select the SHAPE field
  • then hit CTRL + SHIFT + F to open the field calculator.
  • In the field calculator, check the Advanced Option and paste this script in the Pre-Logic VBS Scipt Code text box.
  • Make Sure that the layer index number for the customer feature class is set. This item can be found by searching the code below for 'SET THIS.
  • Type the word Count into the bottom text box and hit OK.
Comment on this Article
19, Jan. 2009
Last Updated ( 02, Jul. 2009 )
Read more...
 
Python! Easy GUI... PDF Print E-mail

Written by Kevin Bell,

There are a lot of options for GUI development with python, but a lot of them require more code than some would like, so enter easyGUI!  In the code below, the GUI part is ONLY the first line in the lauchEnter function. The GUI assigns a string to the variable "caseN". How easy is that?!!  At the end of the script, I use a message box as well, which again is a one liner.

We have scanned traffic accident reports on the network, and looking through the files in windows explorer is a pain, so this code prompts you for a case number, and upon recieving it, it parses off the file extension since our reports can be .tiff or .pdf, then goes and opens the file if we have it, otherwise it tells you that we don't have that case. I put the script on the desktop, so it's a single click, enter casenumber, and get the file.

http://easygui.sourceforge.net/

 

Comment on this Article
07, Jan. 2009
Last Updated ( 07, Jan. 2009 )
Read more...
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 33 - 40 of 130

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for