Showing posts with label ArcGIS. Show all posts
Showing posts with label ArcGIS. Show all posts

Wednesday, August 29, 2012

Unable to reach ArcGIS Server 10.1 Configuration Manager


For web GIS application installs behind a firewall (intranet) ArcGIS Server communicates with HTTP port 6080 by default (Ports used by ArcGIS Server).  Typically you can navigate to your server local host or loopback IP address of port 6080 to reach the ArcGIS Server Configuration Manager (similar to shown below).
http://localhost:6080/arcgis/manager
http://127.0.0.1:6080/arcgis/manager

But what if the page errors out and you cannot reach the ArcGIS Server Configuration Manager? 
There could be many things causing this problem which are relatively simple to correct, but not always simple to diagnose.  Here are a few recommendations to help diagnose and correct this problem:

1.      The first and most obvious item to check is your Windows Network Diagnostics.  Troubleshooting with Windows Network Diagnostics might help reveal the underlying issue.  You might get an error message like: "The remote device or resource won't accept the connection", or “The device or resource (127.0.0.1) is not set up to accept connections on port “6080”.  (shown below).


This type of error is indicative of an implicitly blocked port or similar issue.  The fix could be as simple as adding an exception to your firewall for port 6080 (TCP).  If that fixes it, great!  If not, read on…
2.       A second item to check would be the "Hosts" file.  In very rare situations this could be the culprit.   Perhaps some network configurations were made or you encountered network problems elsewhere since initially installing ArcGIS Server.  The "Hosts" file could be pointing to an improper IP address, instead of  the desired one.  If this is the case, simply alter the IP address in the "Hosts" file to point back to your local host or loopback IP address for port 6080 and it should be repaired.
Of course there could be many other reasons you are having problems, but since the documentation on this subject is limited, I figured it would be worth sharing some of the solutions we have used.  Hopefully you find this helpful.

Friday, November 12, 2010

Python Tip: Coordinate Clean Up

If you create point features from coordinates stored in flat tables you probably find cases where the longitude and latitude are reversed or a negative sign is missing.  This happens frequently if the source of the data is from a non-GIS user.  What can make fixing these mistakes more difficult is if the errors are not consistent through out the table.  The following Python example will switch the longitude and latitude if necessary and add negative signs if missing.  Note: This code is only useful if all the points are with in the same hemisphere.  If the points are located across the globe, a solution to this problem is much more difficult.

First, import the modules and create the geoprocessor:

import sys, string, os, arcgisscripting

gp = arcgisscripting.create()
gp.OverWriteOutput = 1

Next, create an Update Cursor:

rows = gp.UpdateCursor(r"C:\Project\sample.gdb\table")
row = rows.Next()

Now you need to loop through each row in the table and get the longitude and latitude values.  Note that the XCOORDINATE and YCOORDINATE are the name of the field ins the table:

while row:
     xCoord = row.XCOORDINATE
     yCoord = row.YCOORDINATE

We will need to switch the longitude and latitude if they are reversed.  We do this by checking to see if the longitude is within a valid range.  In this all points should fall with 30 to 50 degrees West Longitude.  If they do not, we assume that they are switched and switch them:

      if xCoord > 30 and xCoord < 50:
          row.XCOORDINATE = yCoord
          row.YCOORDINATE = xCoord
          xCoord = yCoord

We use simpler logic to check for a missing negative sign.  In this case the longitude should be negative so we check.  If it is not, we make it negative:

     if xCoord > 50:
          xCoord = xCoord - (xCoord * 2)
          row.XCOORDINATE = xCoord

Now that the changes have been made if necessary we update the row and move to the next row:

     rows.UpdateRow(row)
     row = rows.Next()

Finally, delete the cursor:

del row
del rows

As you can see the values will change depending on the location of your points, but this general logic should solve most of your problems.  And like all examples, there are several ways to do most of these steps.

Friday, September 17, 2010

Migrating Data from Trimble GPS Pathfinder Office to an ESRI Geodatabase

If you use Trimble GPS Pathfinder Office, you have probably discovered that it does not export data directly into an ESRI geodatabase.  This can be a significant problem, especially if you have a large data dictionary with many features.  However, GPS Pathfinder Office does allow you to export each feature to an individual shapefile.  Using Python, we can quickly move all of the data in the shapefiles into a geodatabase.  The following script will do this automatically for you.  Some important notes, however, are:

1.) This script was written quickly to get the job done.  There are many ways this can be done, and this is only one of them.
2.) The data model of the geodatabase must match the data dictionary exactly.  This is important because the script only works if it does.  Actually, the fields do not have to have the same name, but they need to be in the same order.  You will see below why this is important.
3.) The feature classes in the geodatabase must mach the names of the features in the data dictionary.  For example, if it is called "Roads" in the data dictionary, the feature class shoudl be called "Roads" as well.
4.) All of the feature classes must be in the same data set.

Now let's get started.  First import your modules, create a geoprocessing object, and load the Data Management Toolbox:

import sys, string, os, arcgisscripting

gp = arcgisscripting.create(9.3)

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

Next get a list of all the shapefiles in the output directory from GPS Pathfinder Office:

fileList = os.listdir("C:\\Project\\Data_Dictionary\\SHP")

Now we need to iterate through the list of files in the directory.  We first need to determine if the file is a shapefile by getting its extension:

for i in fileList:
    splitText = os.path.splitext(i)

Now we need to check if the file extension is a shapefile, create and empty string for creating the Append parameter, and start a counter that will be used to keep track of the position of the fields:

    if splitText[1] == fileExt:
        fieldMap = ""
        count = -1

Now we need to get a list of the fields in the matching feature class.  If the shapefile does not match a feature class, it will be skipped:

        try:
            fields = gp.ListFields("C:\\test.mdb\\Data\\" +\
                splitText[0])
        except:
            continue

Let's loop through the fields in the feature class and match them up to the shapefile.  We also need to increase the counter:

        for field in fields:
            count += 1

It is actually not possible to make the data model exactly the same because the feature class requires an OBJECTID and Shape field.  To overcome this we will skip these fields in the field mapping:

            if field.Name == "Shape" or 
            field.Name == "OBJECTID":
                break

We must now get the information from the shapefile:

            else:
                gp.MakeFeatureLayer("C:\\SHP\\" + i,
                    "tempLayer")
                desc = gp.Describe("tempLayer")
                fieldInfo = desc.FieldInfo
               
In the parameter for the Append tool, we need to sepearte each field with a semicolon except for the last field:

                if count > 2:
                    fieldmap += ";"

Now we build our field mapping string from all the information we just collected.  Here you will see we use the counter as the index number of the field:

                fieldMap += field.Name + " '" + field.Name +\
                   "' true true false " +\
                   str(field.Length) + " " + field.Type +\
                   " 0 0 ,First,#,C:\\SHP\\" + i + "," +\
                   fieldInfo.GetFieldName(count) + ",-1,-1"

We can now finish the script by using the Append tool to append the records from the shapefile to the feature class:

        gp.Append_management("C:\\SHP\\" + i,
           "C:\\test.mdb\\Data\\" + splitText[0], "NO_TEST",
           fieldMap, "")

As you can tell, this not necessarily the most efficient way to do this.  I have since rewritten this process using C# to create a more stable tool, however, this fairly simple script can save you quite a bit of time.  I encourage you to modify it and make it work even better.

Friday, August 20, 2010

Python Tip: Iterating through a feature class

After you have mastered creating Python scripts to perform geoprocessing tasks on single feature classes, you will probably realize that you will often come across cases where you will want to perform the same tasks on all the features in a feature class, such as adding a field, adding a prefix or suffix to the name, etc.  Accomplishing this is very easy.  You ill need to iterate through a feature class using the ListFeatureClasses function.  I will give you an example that capitalizes the names of the feature classes in a feature class.  Start by importing the proper modules:

import sys, string, os, os.path, arcgisscripting

Next add the toolbox with the Rename tool:

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

Set the workspace to the feature class you wish to edit:

gp.workspace = "Database Connections\\GIS.sde\\Data"

Call the ListFeatureClasses function and move to the first feature class:

fcList = gp.ListFeatureClasses ("*", "all")
fc = fcList.Next()

Now loop through and rename each feature class:

while fc <> None:
     gp.Rename_management(gp.workspace + "\\" + fc, 
                          gp.workspace + "\\" + fc.upper() \
                          + "_temp", "FeatureClass")
     gp.Rename_management(gp.workspace + "\\" + fc.upper() \
                          + "_temp",  
                          gp.workspace + "\\" + fc.upper(),
                          "FeatureClass") 

     fc = fcList.Next()

Because ArcGIS is not case-sensitive, we had to temporarily rename the feature classes with "_temp" at the end, and then rename them again and capitalize them.  Also, remember to call the Next function to move to the next record or you will be stuck in an infinite loop.

In this case, we ran through every feature class but using the wild card parameter, you can select a subset of the feature classes.  Other similar functions exist that are also useful such as ListDatasets and ListTables.  I recommend that you read more about these functions here.

Friday, August 6, 2010

3 Quick Python Tips to Make Geoprocessing Easier


1. Ignoring escape characters
 
When you export a Python script from Model Builder, you have probably noticed that the “\” in the directory paths are modified in two ways, either “/” or “\\”.  This is because “\” is an escape character.  Basically, “\” tells Python to look at the following character and do something special.  For example “\n” tells Python to start a new line.  However, if you are like me, you usually copy and paste a file path and it is a hassle to have to change every occurrence of “\”.  Luckily there is away to tell Python to ignore the “\” in a string as an escape character.  You can do this by placing an “r” directly in front of the string.  So here are three ways to create the same string:
 
r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes"
"C:/Program Files/ArcGIS/ArcToolbox/Toolboxes"
"C:\\Program Files\\ArcGIS\\ArcToolbox\\Toolboxes"


2. Getting the directory location of the current script

When creating batch scripts that you will reuse frequently for files in various locations, it can be time consuming to modify the file directory before running the script every time.  One method of making this step easier is by placing the script in the same directory as the files you want to process.  To do this, you can have the script use the directory it is located in using the getcwd function.  This function returns the directory that the script is located in.  First import the os module and then call the getcwd function:

import os

directory = os.getcwd()


3. Create a data stamp

When processing file, you may want to create a date stamp on the end of the file name or write the date to a txt file.  Creating a date stamp is fairly easy First import the time module, then call the localtime function to return the current date and time on the system.  This example returns a string in the “MM_DD_YYYY format:

import time

t = time.localtime()

date = str(t[1]) + "_" + str(t[2]) + "_" + str(t[0])