-- This scripts add some features to the ones defined by load_topology.sql
-- and then runs some binary predicates on them.
--

#define DO_POINT_POINT_INTERSECTS 1
#define DO_POINT_LINE_INTERSECTS 1
#define DO_LINE_LINE_INTERSECTS 1
#define DO_POINT_POLYGON_INTERSECTS 1
#define DO_LINE_POLYGON_INTERSECTS 1
#define DO_POLYGON_POLYGON_INTERSECTS 1
#define DO_POINT_POINT_EQUALS 1
#define DO_LINE_LINE_EQUALS 1
#define DO_POLYGON_POLYGON_EQUALS 1

BEGIN;

#if DO_POINT_POINT_INTERSECTS

-- Detect intersections between traffic_signs 

SELECT 'POINT/POINT INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.traffic_signs a, features.traffic_signs b
	WHERE a.oid < b.oid AND @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);

#endif


#if DO_POINT_LINE_INTERSECTS

-- Detect intersections between city_streets and traffic_signs

SELECT 'POINT/LINE INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.traffic_signs a, features.city_streets b
	WHERE @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);

#endif


#if DO_LINE_LINE_INTERSECTS

-- Detect intersections between city_streets

SELECT 'LINE/LINE INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.city_streets a, features.city_streets b
	WHERE a.oid < b.oid AND @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);
#endif

#if DO_POINT_POLYGON_INTERSECTS

-- Detect intersections between traffic_signs and land_parcels

SELECT 'POINT/POLY INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.traffic_signs a, features.land_parcels b
	WHERE @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);
#endif

#if DO_LINE_POLYGON_INTERSECTS

-- Detect intersections between city_streets and land_parcels

SELECT 'LINE/POLY INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.city_streets a, features.land_parcels b
	WHERE @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);
#endif

#if DO_POLYGON_POLYGON_INTERSECTS

-- Detect intersections between land_parcels and land_parcels

SELECT 'POLY/POLY INTERSECTS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.land_parcels a, features.land_parcels b
	WHERE a.oid < b.oid AND @SCHEMA@intersects(a.@COLUMN@, b.@COLUMN@);
#endif

#if DO_POINT_POINT_EQUALS

SELECT 'POINT/POINT EQUALS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.traffic_signs a, features.traffic_signs b
	WHERE a.oid < b.oid AND @SCHEMA@equals(a.@COLUMN@, b.@COLUMN@);

#endif

#if DO_LINE_LINE_EQUALS

SELECT 'LINE/LINE EQUALS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.city_streets a, features.city_streets b
	WHERE a.oid < b.oid AND @SCHEMA@equals(a.@COLUMN@, b.@COLUMN@);

#endif

#if DO_POLYGON_POLYGON_EQUALS

SELECT 'POLYGON/POLYGON EQUALS' as operation;

SELECT a.feature_name, b.feature_name FROM 
	features.land_parcels a, features.land_parcels b
	WHERE a.oid < b.oid AND @SCHEMA@equals(a.@COLUMN@, b.@COLUMN@);

#endif




END;

