Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Suppose a programmer has no knowledge of GIS, but wants to leverage his/her programming skills to get into GIS. Please list different GIS platforms, packages, etc. that use a particular language.

(I was thinking, as suggested, about doing a simple test of the code formatting capability of StackExchange. I figure this might be done in the context of a useful answer.)

When you answer, if the language is one of those listed below, please post a code snippet and test the formatting to make sure it works. Here's an excerpt from Jeff Atwood's answer on meta-stackoverflow.

The spec is:

<!-- language: lang-or-tag-here -->

    code goes here

<!-- language: lang-or-tag-here -->

    code goes here

You may use either a tag or a prettify language code to specify, though prettify language codes are always guaranteed to work regardless of what language the tag happens to be set to.

Use <!-- language-all: lang-or-tag --> to use the given highlighting for all the following code blocks.

The complete list of supported prettify code languages is:

  • lang-none
  • lang-default
  • lang-bsh
  • lang-c
  • lang-cpp
  • lang-cs
  • lang-csh
  • lang-css
  • lang-hs
  • lang-html
  • lang-java
  • lang-js
  • lang-lisp
  • lang-lua
  • lang-ml
  • lang-perl
  • lang-php
  • lang-py
  • lang-proto
  • lang-rb
  • lang-scala
  • lang-sh
  • lang-sql
  • lang-vb
  • lang-xml
share|improve this question
add comment

8 Answers

Some geospatial scripting languages:

1) Python/Jython

Python/Jython alone:

Python and Jython can be used alone for processing geospatial data without any software, using modules like osgeo (GDAL / OGR), PySAL, Shapely, Fiona, Pyshp,..., see Python Package Index, Topic:GIS or Geoscript (Jython). There are many examples on GST

as scripting language in applications

QGIS, GRASS GIS, GvSIG, OpenJump or Geoserver (and ArcGIS, see above) use Python/Jython for scripting:

  • Quantum GIS ( Python, 1.8, changes in master version)
from qgis.core import *
layer = qgis.utils.iface.activeLayer()
for elem in layer.selectedFeatures():
        geom= elem.geometry()
        attrs = elem.attributeMap()
  • GRASS GIS (Python)
from grass.script import raster as grassr
grassr.raster_info('s_newfrst3@moi')
{'north':118869.900569, 'timestamp': '"none"', 'min': -456.08587646484398,
'datatype': 'FCELL', 'max': 265.500732421875, 'ewres':
 14.008076920000001, 'vertical_datum': '', 'west': 164160.653425,
 'units': '', 'title': ' (s_newfrst3)', 'east': 176641.849961, 'nsres':
  13.976472729999999, 'south': 112552.534895}
  • GvSIG (Jython)
from gvsig import *
layer = currentLayer()
features = layer.features()
for feature in features:
  geom = feature.geometry()
  values = feature.getValues()
  • OpenJump (Jython)
from org.openjump.util.python.JUMP_GIS_Framework import *
layer = getSelectedLayers()
for i in layer.iterator():
    print layer.name  
# first element of the layer
fc = layer[0].featureCollectionWrapper
for elem in range(fc.size):
    obj = fc.features[elem] 
    geom = obj.getGeometry()
  • GeoServer (Jython)
from geoserver import Catalog
cat = Catalog('aff_geol')
print cat.stores()
[u'affleurements', u'cartes']
st = cat['affleurements']
print st.layers()
[u'affs']
l = st['affs']
print l.count()
3214
print l.bounds()
(107206.74,148102.45,114110.46,157514.40, EPSG:31370)

and you can also use other Java libraries like the Java Topology Suite( Jython):

import sys
sys.path.append('.../jts-1.8.0/lib/jts-1.8.jar')   
from com.vividsolutions.jts.geom import Point

2) Bash

GRASS GIS uses Bash (shell and scripts (.sh))

GRASS 6.4.2 (geol):~ > v.out.ascii in=ligneprofil format=standard | grep '^ '|\r.profile -c in=MNT res=30 output=profil.pts

3) R (no prettify code language)

You can use R for all geospatial treatments, see CRAN Task View: Analysis of Spatial Data:

library(maptools)
geol <-readShapePoly("cal.shp")
library(rgdal)
geol = readOGR(dsn=".", layer="cal")
library(PBSmapping)
geol = importShapefile("cal.shp")
library(shapefiles)
geol <- read.shapefile("cal")
# PostGIS
geol = readOGR("PG:dbname=test", "cal")

but GRASS GIS can also uses R directly:

GRASS 6.4.2 (geol):~ > R
R version ....
> library(spgrass6) 
> G <- gmeta6() # paramètres de Grass, région etc.
> montrait <- readRAST6(c("geologie", "mnt"),cat=c(TRUE, FALSE),  ignore.stderr=TRUE,plugin=NULL)

4) BeanShell(Java)

OpenJump can also use Beanshell (console or script)

layer = wc.layerManager .getLayer("road").featureCollectionWrapper;
getLongest() {
    max = -1;
    for (f : layer.features) { length = f.geometry.length; if (f.geometry.length > max) {max = length; result = f;}
}
return result;
print(getLongest().ID);

5) Groovy (Java), Scala and JavaScript

You can use theses languages with GeoScript, see examples

6) JEQL Query Language

As shown by Martin Davis (label jeql)

shapefileReader t file: "agder/agder_buffer.shp";
t = select geomUnionMem(GEOMETRY) g from t;
ShapefileWriter t file: "result.shp";
share|improve this answer
add comment

Old school GIS without computers. lang-none

    Overlay acetate on paper maps, buffer with rulers,
    symbolize with dry-erase markers.
    No computers, so no language needed.
share|improve this answer
add comment

C# can be used to program ArcGIS. With ArcObjects this involves dealing with a lot of COM interop, so any knowledge there would be very helpful.

C# can also be used (without dealing with much interop) in the ArcGIS for WPF and the ArcGIS for Silverlight SDK's.

public static IPolyline MakePolyline(IPoint p1, IPoint p2)
{
    var polyline = new PolylineClass() as IPolyline;
    ((IZAware)polyline).ZAware = true;
    ((IMAware)polyline).MAware = true;
    polyline.SpatialReference = p1.SpatialReference;
    ((IPointCollection)polyline).AddPoint(p1);
    ((IPointCollection)polyline).AddPoint(p2);
    return polyline;
}
share|improve this answer
add comment

A lot of WebGIS development is done via JavaScript. Here is some sample code using OpenLayers:

        var lon = 5;
        var lat = 40;
        var zoom = 5;
        var map, layer;

        function init(){
            map = new OpenLayers.Map( 'map' );
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
            map.addLayer(layer);

            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            map.addControl( new OpenLayers.Control.LayerSwitcher() );
        }
share|improve this answer
add comment

ArcGIS since 10.0 uses Python via the arcpy module.

Using the Python that comes with ArcGIS:

import arcpy

# Make dictionary of lookup table
dictCityProvince = {}
rows = arcpy.SearchCursor(r"C:\temp\test.gdb\CityProvinceLookup")
for row in rows:
    dictCityProvince[row.CITY] = row.PROVINCE
del row,rows

If this works, then you should be good to go.

share|improve this answer
add comment

Development for the Android Platform is done using Java.

Here is some code from the OsmDroid project:

/**
 * Logs all Location-changes to <code>mRouteRecorder</code>.
 *
 * @author plusminus
 */
private class SampleLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(final Location loc) {
        if (loc != null) {
            if (SampleMapActivity.this.mDoGPSRecordingAndContributing)
                SampleMapActivity.this.mRouteRecorder.add(loc,
                        SampleMapActivity.this.mNumSatellites);

            SampleMapActivity.this.onLocationChanged(loc);
        } else {
            SampleMapActivity.this.onLocationLost();
        }
    }
share|improve this answer
add comment

A lot of projects are developed in C++.

Here is some source code from QGis:

/**
  Open the specified project file; prompt to save previous project if necessary.
  Used to process a commandline argument or OpenDocument AppleEvent.
  */
void QgisApp::openProject( const QString & fileName )
{
  // possibly save any pending work before opening a different project
  if ( saveDirty() )
  {
    // error handling and reporting is in addProject() function
    addProject( fileName );
  }
  return ;
}
share|improve this answer
add comment

C can be used with the ArcSDE C API.

I see that it can be downloaded for 10.1 here, but is not mentioned in the list of API's on the help page. I don't see any online help for 10.1, only 10.0 help.

void check_rc_(SE_CONNECTION Connection, SE_STREAM Stream, LONG rc, 
                 char *comment, LONG line_no, char* file_name) ;
static LONG S_create_layer (SE_CONNECTION connection, CHAR *table,CHAR *keyword,LONG precision);
static LONG S_point_cases(SE_CONNECTION connection,const CHAR* table);
static LONG S_line_cases(SE_CONNECTION connection,const CHAR* table);
static LONG S_polygon_cases(SE_CONNECTION connection,const CHAR* table);

LONG  main(int argc, char *argv[]){
    CHAR            *server, 
                    *user, 
                    *passwd, 
                    *database,
                    *instance,
                    *rslt_layer_name;
    SE_CONNECTION   conn;
    SE_ERROR        error;
    LONG            result;
    BOOL            all_step_passed=TRUE;

    if(argc<7){
        printf("usage: %s <server> <instance> <database> <user> <passwd> <result_layer>",argv[0]);
        exit(1);
    }

    server=argv[1];
    instance=argv[2];
    database=argv[3];
    user=argv[4];
    passwd=argv[5];
    rslt_layer_name=argv[6];

    printf("\nConnecting to SDE server %s:%s as %s\n",server,instance,user);
    result = SE_connection_create( server, instance, database, user, passwd, &error, &conn );
    check_rc_return_on_failure(conn,NULL,result,"SE_connection_create");
    printf("\t---Connected");

    /*Create a layer to store results*/
    printf("\n\nCreating a layer to store results......\n");
    result=S_create_layer (conn,rslt_layer_name,"DEFAULTS",64);
    if(result!=SE_SUCCESS)
        return result;
    else
        printf("\tLayer %s created.\n",rslt_layer_name);

    /*point shapes*/
    printf("\n\n***************************************************************************\n");
    printf("* Generating buffer for point shapes......                                *\n");
    printf("***************************************************************************\n");
    result=S_point_cases(conn,rslt_layer_name);
    if(result!=SE_SUCCESS)
        return result;

    /* line shapes */
    printf("\n\n***************************************************************************\n");
    printf("* Generating buffer for line shapes......                                 *\n");
    printf("***************************************************************************\n");
    result=S_line_cases(conn,rslt_layer_name);
    if(result!=SE_SUCCESS)
        return result;

    /* polygon shapes */
    printf("\n\n***************************************************************************\n");
    printf("* Generating buffer for polygon shapes......                              *\n");
    printf("***************************************************************************\n");
    result=S_polygon_cases(conn,rslt_layer_name);
    if(result!=SE_SUCCESS)
        return result;

    SE_connection_free(conn);

}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.