PostGIS to GeoJSON

SELECT
    row_to_json(feature_collection)
FROM (
    SELECT
        'FeatureCollection'::text as type,
        case
            when
                array_agg(feature_collection_data) is null
            then
                array_to_json(ARRAY[]::varchar[]) 
            else
                array_to_json(array_agg(feature_collection_data))
        end as features
    FROM (
        SELECT
            'Feature'::text as type,
            ST_AsGeoJSON({geomCol})::json as geometry,
            row_to_json((SELECT row FROM (SELECT {properties}) as row)) as properties
        FROM
            {table} as row_data
        WHERE
            {where}
    )  as feature_collection_data
)  as feature_collection;";

Notes:

{geomCol} - geom column to select from or geometry returning call such as ST_GeomFromText('POINT(' || lon || ' ' || lat || ')' ,4326)

{properties} - a comma separated list of columns to select from; can be aliased

{table} - a table to select from

{where} - a where clause if needed

OGC xml schemas to c# classes using xsd.exe

The process of generating c# classes off the xsd is usually rather simple. One needs the xsd.exe utility (for example located here: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools) and then a simple command to get things done:

xsd schema.xsd /c

Sometimes there may be some problems though with missing refs, namespaces and such.

In this example, I will generate classes for WMS 1.3.0 based on the OGC schemas - it is possible to grab them one by one, or all the goodies wrapped as a zip archive.

I have extracted WMS 1.3.0 schemas to f:\wms\schemas, so my command should look like this when in f:\wms (I have copied xsd.exe there too):

xsd schemas\capabilities_1_3_0.xsd /c

Unfortunately there are some problems and classes do not get generated:

The problem here is caused by unresolved references. Xsd was not able to find xlink.xsd. Although there is a xlink schema in OGC repo, this is not the one we're after. The one in question is the mentioned http://www.w3.org/1999/xlink, and its schema definition is http://www.w3.org/1999/xlink.xsd, pretty much as defined in the very beginning of the capabilities_1_3_0.xsd I am trying to process:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.opengis.net/wms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:wms="http://www.opengis.net/wms" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.3.0.2">
	
	<!--
		WMS is an OGC Standard.
		Copyright (c) 2004,2010 Open Geospatial Consortium.
		To obtain additional rights of use, visit http://www.opengeospatial.org/legal/ .
	-->

	<import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd"/>

Unfortunately xsd.exe does not resolve the import automatically, so in order to make it work I just copied the xlinx.xsd to my schemas folder and specified it in the command:

xsd schemas\xlink.xsd schemas\capabilities_1_3_0.xsd /c

Looks like this did the trick and the classes got generated as expected. The complete set of files is here: 

ogc_wms_cs_from_xsd.zip (51.1KB)

GlobalMapper - batch reproject and export geotif to ecw

A simple GlobalMapper script that iterates through all the tiff files in a specified directory, and exports them to ecw in EPSG 2180, 3857 and 4326.

//Exports all the tif files found in the source dir to ecw.
//Reprojects the data to 2180, 3857 and 4326 and the exports it to the appropriate folders

GLOBAL_MAPPER_SCRIPT VERSION=1.00

//Define in / out folders
DEFINE_VAR NAME=source_dir VALUE="C:\here\goes\input\path"
DEFINE_VAR NAME=target_dir VALUE="C:\here\goes\output\path"

//start the loop to iterate through all the files
DIR_LOOP_START DIRECTORY="%source_dir%" FILENAME_MASKS="*.tif" RECURSE_DIR=NO
	//Import the file
	IMPORT FILENAME="%FNAME_W_DIR%"
	
	//assign projection 4326
	LOAD_PROJECTION PROJ=4326
	EXPORT_RASTER FILENAME="%target_dir%\4326\%FNAME_WO_EXT%.ecw" TYPE=ECW BG_TRANSPARENT=YES FORCE_SQUARE_PIXELS=YES
		
	//assign projection 2180
	//Note: gm seems to not properly load 2180, so reading the proj def from a file
	LOAD_PROJECTION FILENAME="%source_dir%\2180.prj"
	EXPORT_RASTER FILENAME="%target_dir%\2180\%FNAME_WO_EXT%.ecw" TYPE=ECW BG_TRANSPARENT=YES FORCE_SQUARE_PIXELS=YES
	
	//assign projection 3857
	//Note: gm seems to not properly load neither 3857 not 900913, so reading the proj def from a file
	LOAD_PROJECTION FILENAME="%source_dir%\3857.prj"
	EXPORT_RASTER FILENAME="%target_dir%\3857\%FNAME_WO_EXT%.ecw" TYPE=ECW BG_TRANSPARENT=YES FORCE_SQUARE_PIXELS=YES
	
	//Unload the loaded data
	UNLOAD_ALL

// End the loop
DIR_LOOP_END

GDAL - assign a projection to a tif

per file:

gdalwarp -t_srs "EPSG:4326" input.tif output.tif

and a batch:

@echo off
mkdir processed
for %%F in (*.tif) do (
	echo processing %%F
	gdalwarp -t_srs "EPSG:4326" %%F processed\%%F
)
pause