Blogs

Creating observations using the Species API

Our Species Platform is designed not just to be a web page, but also an Application Programming Interface (API) that allows other websites and programs to read, create and edit observations.

Creating an Observation requires having an existing Fish and Game Account, logging in successfully, and finally creating the new observation.  For this example I'll be using the Firefox Poster extension.  Let's get started!

Step 1 - Login

First we need to authenticate against Fish and Game Accounts and receive a token to include in our future interactions with the REST API.  We can do both steps at once by posting to the login form with a return path set to receive our token:

https://fishandgame.idaho.gov/ifwis/accounts/user/login?returnUrl=/speci...

Set the content type:

application/x-www-form-urlencoded

And send a standard html payload for username, password and rememberMe flag:

username=myusername&password=mypassword&rememberMe=true

Login

Post this and in the response you'll receive a string that we'll use as a token for all future requests.

Step 2 - Create Observation

Now we need to construct the request to create our observation.

Let's start by adding the token.

Add Token to Header

This token is only for session validation, not authentication.  Forms-based cookies are still needed for authentication, so if building a stand-alone iOS or Android application you'll also need to add the cookie to the request.

 

Now we need to build the payload for the observation.  We can do this as an HTML form, XML or JSON object.  For our example we'll use JSON.

Post to:

https://fishandgame.idaho.gov/species/rest/node.json

Content Type:

application/json

Finding the correct content for the post is a little tricky.  It involves quite a bit of familiarity with the data and our API which is built using Drupal Services.  The documentation will get you started, and examples are useful, but ultimately we are going to have to break this down in a future post line by line.  

In this example we have standard inputs (field_count) with one pattern, select lists and radios (field_count_type) with a slightly different pattern, dates (field_datetime) doing something different still, files (field_file) weirder still, geofield (field_location) with escaped geojson and node references (field_species) which include the primary key of the referenced content.  The good part, is once you understand these oddities, it's the same oddities to create other data stored in Species.

Content:

{
    "type": "observation",
    "field_count": {
        "und": [
            {
                "value": "1"
            }
        ]
    },
    "field_count_type": {
        "und": [
          "Absolute"
        ]
    },
    "field_life_stage": {
        "und": [
          "Mature"
        ]
    },
    "field_life_state": {
        "und": [
          "Alive"
        ]
    },
    "field_location": {
        "und": [
            {
                "geom": "{ \"type\": \"Point\", \"coordinates\":  [-112.0, 43.5] }"
            }
        ]
    },
    "field_location_resource": {
        "und": [
            {
                "value": "Google Maps Click"
            }
        ]
    },
    "field_location_use": {
        "und": [
          "Unknown"
        ]
    },
    "field_observation_method": {
        "und": [
          "Seen",
          "Heard"
        ]
    },
    "field_sex": {
        "und": [
          "Unknown"
        ]
    },
    "field_species": {
        "und": [
            {
                "nid": "[nid:80612]"
            }
        ]
    },
    "field_species_confidence": {
        "und": [
          {
            "value": "100"
          }
        ]
    },
     "field_datetime": {
        "und": [
            {
                "value": {
                   "date": "07/16/2013",
                   "time": "11:14am"
                }
            }
        ]
    },
    "field_file": {
        "und": [
            {
                "fid": ""
            }
        ]
    },
    "field_photo": {
        "und": [
            {
                "fid": ""
            }
        ]
    }
}
 
 
 
 
 
If the post is successful you'll receive a json response with the new id of the observation:

 

You can browse to this location to retrieve an xml version of the new observation:

Append .json to view as a javascript object:

Or remove rest from the url to view and edit as HTML:

This is the first in a series of posts on creating, reading and manipulating content in species through the API.  We'll add links to future posts here of follow the speciesapi tag.

Display Points From a Table: A Step-by-Step Guide

Do you have data points that won’t display right in your GIS map?

This may be the help you need.

Download and View Powerpoint Presentation

Click slide or this link to view Powerpoint Presentation

Definitions of Terms used by IDNHP and IFWIS

Links to downloadable files have been added to the IFWIS website.  A workbook of acronyms, agency codes, and definitions was added to the Species Diversity page.  A text document was added to the Obtain Information page, explaining the terms used in the downloadable county lists of rare and sensitive species.

 

Create a Buffer for a KML in Google Earth

Create a user-defined buffer around point, line, or polygon KMLs has never been easier!

1) Make sure that your Google Earth data is saved as a KML, not KMZ

2) Open this website: http://www.geo-news.net/index_buffer.php

          

3) Select your buffer type (line, point, or polygon)

4) Select the KML you would like to buffer and choose a buffer distance (in meters). Click the globe with the up arrow to upload your KML file.

                                    

5) A new KML will be created and available via a link at the top of the screen.

            

6) Click the link, save the KML to a location of your choosing and open in Google Earth!

MS Access Query to determine if 1+ fields of a subset of fields is not null

I recently encountered an issue where I tried to determine which records for any of 7 out of 12 Forest Service National Forests contained data for a query.  Region 4 of the USFS has 12 NFs, of which 7 have boundaries within Idaho.  For a list of sensitive species occurring in the region, I wanted to determine which species occurred in 1 or more of the forests that occur in Idaho.  Currently, R4 indicates 231 sensitive species, but only 56 occur in forests within Idaho.

With my original query, I simply put `Is Not Null' in the `or:' row of the query design view, but this resulted in no records being returned.  It appeared that something needed to be in the `Criteria:' row of query design, but when I did this, then put `Is Not Null' in the `or' row going straight across for each field desired, only records meeting the `Criteria:' rule were returned.  Example of failed query shown below:

It ended up that the query rules needed to be "tiered" or staggered in the query design view, with each OR statement completely encapsulated with parenthesis, resulting in the following GOOD SQL query:

 

SELECT [Tbl_USFS-R4--July_2011].ID, [Tbl_USFS-R4--July_2011].Type, [Tbl_USFS-R4--July_2011].Species, [Tbl_USFS-R4--July_2011].Common, [Tbl_USFS-R4--July_2011].Boise_NF, [Tbl_USFS-R4--July_2011].Caribou_NF, [Tbl_USFS-R4--July_2011].Challis_NF, [Tbl_USFS-R4--July_2011].Payette_NF, [Tbl_USFS-R4--July_2011].Salmon_NF, [Tbl_USFS-R4--July_2011].Sawtooth_NF, [Tbl_USFS-R4--July_2011].Targhee_NF
 
FROM [Tbl_USFS-R4--July_2011]
 
WHERE ((([Tbl_USFS-R4--July_2011].Boise_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Caribou_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Challis_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Payette_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Salmon_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Sawtooth_NF) Is Not Null)) OR ((([Tbl_USFS-R4--July_2011].Targhee_NF) Is Not Null));
 
Tiered Query to determine if any of a subset "is not null"
 

 

Display BLM PLSS (township, range, section) & USGS Quadrangle data in Google Earth using Earth Survey Tools

Have you ever been looking for a feature in Google Earth & thought, boy this would be so much easier if I could search for it by township, range, section.  Well, now you can!  Just use the Earth Survey Plugin (ESPlugin).

What all does the Earth Survey Plugin have to offer:

  • Section Geocoder: search by point or township,range, section. Link to the BLM General Land Office records webpage which provides "live access to Federal land conveyance records for the Public Land States, including image access to more than five million Federal land title records issued between 1820 and the present. [They] also have images related to survey plats and field notes, dating back to 1810."
  • Address Geocoder: get address information for placemarks and add, customize, and save placemark data.
  • Overlays: drive-time (5, 10, and 15 minute) polygons; BLM townships, principal meridians, and special surveys; USGS quadrangle index and topo maps.
  • Layers: borders (counties, states, etc.), roads, buildings (not available in all cities), trees (not available in all cities), and terrain

Check out all of Earth Survey's tools at: http://www.metzgerwillard.us/EarthSurvey.html

 

Geospatial PDF?!? How to Create a Geospatially Aware PDF

 

Yes, it is true!  You can make a PDF map spatially aware (aka georeferenced).  Geospatial PDF’s allow users to obtain latitude and longitude coordinates, turn data layers on and off, view a selected features attributes, and to query and highlight data.  This tutorial will explain how you create a spatially aware PDF map from ESRI ArcMap.  Just follow these easy steps!

1) Obtain the latest version of Adobe Reader (for free) at: http://get.adobe.com/reader/. NOTE: This tutorial uses Adobe Reader 10 so if you are using a later or newer version, some of the menus, etc. may be different.

2) Once you have created your map in ArcMap, select Export Map… from the File menu. Choose PDF from the ‘Save as type:” dialog box. If it is not already expanded, expand the Options menu at the bottom of the Export Map dialog box. Select the Advanced tab.  In the Layers and Attributes drop-down menu select ‘Export PDF Layers and Feature Attributes’. Also check the box in front of ‘Export Map Georeference Information’. 

 

3) Open your exported map in Adobe Reader.  Add the Model Tree to the Navigation Pane running down the left side of the Reader by right-clicking the panel.

 

4) Start exploring! 

 

 

TOGGLE LAYERS ON & OFF

Click on the Layers icon in the Navigation Panel.

 

 

You can turn layers/labels on or off by clicking the Eye icon to the left of a group of or individual layers.

 

VIEW ATTRIBUTE DATA

Click on the Model Tree icon in the Navigation Panel.

 

Select a feature from the list to see its attributes (NOTE: These are the same attributes that appear in the attribute tables in ArcMap. If there is a field that is turned off in your ArcMap attribute table, it will also not appear in the PDF). The feature will also be highlighted in the map.

 

You can also select a feature with your mouse on the map to view its attributes in the Model tree. To do so, you must have the Object Data tool on. To turn this tool on: from the Edit menu, select Analysis, and then Object Data Tool.

 

Finally, using the Find tool is also a simple way to query for data.  Simply type the name of the feature into the Find tool or Advanced Search search box.  If there is more than one feature that meets the criteria, it will be listed on the screen.  To see the attributes of a specific feature, select it from the search results list.

 

FIND LATITUDE AND LONGITUDE COORDINATES

To turn this tool on: from the Edit menu, select Analysis, and then Geospatial Location Tool. The location of the cursor while be shown in a text box at the bottom of the screen.

 

HELPFUL FACTS AND TIPS FROM THE ArcGIS RESOURCES WEBPAGE

http://resources.arcgis.com/en/help/main/10.1/index.html#/Exporting_to_PDF/00sm00000007000000/

· Each data frame will have its own folder in the tree view of the PDF that contains all the layers and the data frame graphics (neatline, background) associated with it.

· Text, picture, or north arrow elements added to a layout become part of a layer called Other. It contains all the graphics and marginalia that are not part of a data frame.

· Each group layer will be represented as a folder in the tree view, and the contents of the group layer will be presented within the group layer.

· Layers that cause rasterization, such as transparent layers, or layers that use a picture fill symbology consolidate all the layers below them into a single layer with the name Image.

· If a layer contains picture marker or picture fill symbology, use the option Vectorize picture markers/fills, found on the Format tab of the Options panel. This prevents rasterization of layers below picture markers and fills.

· Raster layers, such as orthophotos, consolidate all layers below them into a single Image layer. Place raster layers lower in the ArcMap table of contents to avoid this problem.

· Graphic or text elements added to the data frame's default graphics layer from data view become a layer called <Default>. These are displayed above the layers in the data frame. If multiple annotation groups exist (check this on the Drawing > Active Annotation Target menu command on the Draw toolbar) and their contents are in the data view, each individual annotation group becomes a separate layer above the <Default> layer. This is a good way to add focus areas or graphics that emphasize or mask certain features in the data view.

· Backgrounds or drop shadows added to the data frame may become separate graphic elements and may be rendered multiple times as graphics. For example, if a data frame has a colored background, and the layout has a different colored background, the data frame's background may be rendered once to the data frame's Graphics or ArcGIS Layer and again to the layout's Graphics layer or ArcGIS Layer.

· Dynamic labels (not using annotation) in each data frame are rendered separately as part of a layer called Labels.

· Geodatabase annotation is displayed as a separate layer in the PDF. Map annotation is consolidated into the layer for the annotation group in which it belongs.

· When labels are converted to annotation, they are automatically placed in their own named annotation group and render separately from the<Default> group.

· Data frames and other layout elements are rendered in draw order when exported to PDF. Therefore, the topmost layout element in the map is the first element in the resultant PDF table of contents. Use the Bring Forward and Send Backward commands from the Draw toolbar to change the draw order of layout elements.

ENJOY!!!

ArcGIS 10.x tip! Overwrite previous outputs from geoprocessing

Do you need to geoprocess the same file again and again.  If only you could simply overwrite the old output file!  Do you end up with files like 'Clip', 'Clip1', 'Clip2'...when you only really need one file named 'Clip'?  Well, here's how to remedy all the duplicate files.  You can set up the Geoprocessing options to overwrite previous outputs.    

NOTE!  If you are person that likes all these copies, I don't recomend setting up the overwrite option.  You may accidentally lose data by overwriting a previous version.  Use this with caution, but be prepared for cleaner GIS directories.

On the menu bar click, Geoprocessing and Geoprocessing options-

An options box will appear.  Simply CHECK the 'Overwrite the outputs of the geoprocessing operations' and OK.  You can now geoprocess files and overwrite previous versions under the same name!  (Be sure to check out some of the other options - you might find something else really useful.)

  

ArcGIS 10.1 TIP: Setting Projections as 'Favorites' in ArcGIS 10.1 - *NEW* in 10.1

New in 10.1!

Tired of scrolling through all the possible projections when you only use about 3 or 4 of them?  In ArcGIS 10.1 you can now save commonly used projections as a ‘favorite’.

Next time you are specifing a projection for a dataset you can mark the projection as a 'favorite' by simply clicking the 'star icon' in the top right corner of the dialog box.

Next time you need to specify that projection, simply look for it within the 'favorites' section.

 

 

 

ArcMap 10.1 - Edit the Service Layer Credit

In ArcMap 10.1 if you add a basemap to a mapping project, a service layer credit for the basemap (or any dataset streamed as a service from ArcGIS online) automatically shows up in the Layout View. 

The position, font, color, size, etc. of the service layer credit may not be to your liking. To edit the service layer credit in Layout View, go to the Insert menu, select Dynamic Text --> Service Layer Credits.  The credits textbox will become editable/moveable.  You cannot just delete the credits textbox. Due to licensing agreements, it will just show up again.