Subject | RE: [firebird-support] Spatial extensions for Firebird |
---|---|
Author | Nigel Weeks |
Post date | 2006-10-23T01:10:23Z |
It's easy to build, and far more flexible than implementing it in the
engine.
Imagine needing to store something the engine didn't support:
Here's a quick sample of some tables:
/* ===================
* geoAttrib table
* Provides extensible storage for polygons and points
* ===================
*/
CREATE TABLE tbl_geoattrib (
int_attribid INTEGER NOT NULL,
str_attribname VARCHAR(128) NOT NULL, /* Give the metadata attribute a
nice name */
str_valuetype VARCHAR(16) default 'text', /* Type of value to expect
the user to supply */
PRIMARY KEY(int_attribid)
);
CREATE GENERATOR GEN_TBL_GEOATTRIB;
/* ===================
* geoPoint table
* A single point in 3D space(can default to 2D with Z=0)
* ===================
*/
CREATE TABLE tbl_geopoint (
int_pointid NUMERIC(18,0) NOT NULL,
flt_x NUMERIC(18,15) NOT NULL, /* Can store 0-365 degrees, with 15
decimals of precision(3mm n the earth surface) */
flt_y NUMERIC(18,15) NOT NULL,
flt_z NUMERIC(18,15) default 0 NOT NULL,
PRIMARY KEY(int_point)
);
CREATE GENERATOR GEN_TBL_POINT; /* Sequence for point ID's */
/* ===================
* geoPointExt
* Store additional metadata about a point
* ===================
*/
CREATE TABLE tbl_geopoint_ext (
int_pointid NUMERIC(18,0) NOT NULL,
int_attribid INTEGER NOT NULL,
int_value NUMERIC(18,0), /* integer value storage */
flt_value NUMERIC(18,15), /* decimal value storage */
str_value VARCHAR(512), /* text value storage */
blb_value BLOB SUB_TYPE TEXT, /* Bulk storage of no specific type */
PRIMARY KEY(int_pointid, int_attribid),
FOREIGN KEY(int_pointid) REFERENCES tbl_geopoint(int_pointid),
FOREIGN KEY(int_attribid) REFERENCES tbl_geopoly(int_attribid)
);
/* ===================
* geoPoly table
* A metadata table about a polygon
* Can be extended with geopoly_ext entries
* ===================
*/
CREATE TABLE tbl_geopoly (
int_polyid NUMERIC(18,0) NOT NULL,
str_polytype VARCHAR(8) default 'simple' NOT NULL, /* simple (box),
normal(star), complex(overlapping lines) */
flt_tlxbound NUMERIC(18,15), /* Top left X of bounding box */
flt_tlybound NUMERIC(18,15), /* Top Left Y of bounding box */
flt_tlzbound NUMERIC(18,15), /* TopLeft Z of bounding box */
flt_brxbound NUMERIC(18,15), /* Bottom Right X of bounding box */
flt_brybound NUMERIC(18,15), /* Bottom Right Y of bounding box */
flt_brzbound NUMERIC(18,15), /* Bottom Right Z of bounding box */
PRIMARY KEY(int_polyid)
);
CREATE GENERATOR GEN_TBL_GEOPOLY;
/* ===================
* geoPolyExt table
* Can add more metadata about a polygon(type:river, agri-status:desert,
etc )
* ===================
*/
CREATE TABLE tbl_geopoly_ext (
int_polyid NUMERIC(18,0) NOT NULL,
int_attribid INTEGER NOT NULL,
int_value NUMERIC(18,0), /* integer value storage */
flt_value NUMERIC(18,15), /* decimal value storage */
str_value VARCHAR(512), /* text value storage */
blb_value BLOB SUB_TYPE TEXT, /* Bulk storage of no specific type */
PRIMARY KEY(int_polyid, int_attribid),
FOREIGN KEY(int_polyid) REFERENCES tbl_geopoly(int_polyid),
FOREIGN KEY(int_attribid) REFERENCES tbl_geopoly(int_attribid)
);
/* ===================
* geoPolyPoints table
* The actual points of a polygon
* includes an ordering integer
* ===================
*/
CREATE TABLE tbl_geopolypoints (
int_polyid NUMERIC(18,0) NOT NULL,
int_pointid NUMERIC(18,0) NOT NULL,
int_order INTEGER default 0 NOT NULL,
PRIMARY KEY(int_polyid,int_pointid),
FOREIGN KEY(int_polyid) REFERENCES tbl_geopoly(int_polyid),
FOREIGN KEY(int_pointid) REFERENCES tbl_geopoint(int_pointid)
);
Finds polygon in a 2d viewport (0>x>10, 0>y>10):
select gPoly.int_polyid from tbl_geopoly gPoly
JOIN tbl_geopolypoint gPolyPoint
ON gPoly.int_polyid = gPolyPoint.int_polyid
JOIN tbl_geopoint gPoint
ON gPolyPoint.int_pointid = tbl_geopoint.int_pointid
WHERE
gPoint.flt_x between '0' and '10' AND gPoint.flt_y between '0' and '10';
You can then write stored procedures to test if a point is inside a
polygon, using standard graphics approaches (e.g. scribe an imaginary line
to the right, and count how many times it intersects with a polygon
edge(calculated via the gradient of a slope at the imaginary line's y
value)).
Have fun!
Nige.
-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com]On Behalf Of bruceeglington2
Sent: Saturday, 21 October 2006 5:43 AM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Spatial extensions for Firebird
Good day
Are there spatial extensions available for Firebird. Something
similar to the Geometry Class in MySQL or as in PostGIS? I have found
some discussion about the need for this in 2004 but nothing since.
Bruce
[Non-text portions of this message have been removed]
engine.
Imagine needing to store something the engine didn't support:
Here's a quick sample of some tables:
/* ===================
* geoAttrib table
* Provides extensible storage for polygons and points
* ===================
*/
CREATE TABLE tbl_geoattrib (
int_attribid INTEGER NOT NULL,
str_attribname VARCHAR(128) NOT NULL, /* Give the metadata attribute a
nice name */
str_valuetype VARCHAR(16) default 'text', /* Type of value to expect
the user to supply */
PRIMARY KEY(int_attribid)
);
CREATE GENERATOR GEN_TBL_GEOATTRIB;
/* ===================
* geoPoint table
* A single point in 3D space(can default to 2D with Z=0)
* ===================
*/
CREATE TABLE tbl_geopoint (
int_pointid NUMERIC(18,0) NOT NULL,
flt_x NUMERIC(18,15) NOT NULL, /* Can store 0-365 degrees, with 15
decimals of precision(3mm n the earth surface) */
flt_y NUMERIC(18,15) NOT NULL,
flt_z NUMERIC(18,15) default 0 NOT NULL,
PRIMARY KEY(int_point)
);
CREATE GENERATOR GEN_TBL_POINT; /* Sequence for point ID's */
/* ===================
* geoPointExt
* Store additional metadata about a point
* ===================
*/
CREATE TABLE tbl_geopoint_ext (
int_pointid NUMERIC(18,0) NOT NULL,
int_attribid INTEGER NOT NULL,
int_value NUMERIC(18,0), /* integer value storage */
flt_value NUMERIC(18,15), /* decimal value storage */
str_value VARCHAR(512), /* text value storage */
blb_value BLOB SUB_TYPE TEXT, /* Bulk storage of no specific type */
PRIMARY KEY(int_pointid, int_attribid),
FOREIGN KEY(int_pointid) REFERENCES tbl_geopoint(int_pointid),
FOREIGN KEY(int_attribid) REFERENCES tbl_geopoly(int_attribid)
);
/* ===================
* geoPoly table
* A metadata table about a polygon
* Can be extended with geopoly_ext entries
* ===================
*/
CREATE TABLE tbl_geopoly (
int_polyid NUMERIC(18,0) NOT NULL,
str_polytype VARCHAR(8) default 'simple' NOT NULL, /* simple (box),
normal(star), complex(overlapping lines) */
flt_tlxbound NUMERIC(18,15), /* Top left X of bounding box */
flt_tlybound NUMERIC(18,15), /* Top Left Y of bounding box */
flt_tlzbound NUMERIC(18,15), /* TopLeft Z of bounding box */
flt_brxbound NUMERIC(18,15), /* Bottom Right X of bounding box */
flt_brybound NUMERIC(18,15), /* Bottom Right Y of bounding box */
flt_brzbound NUMERIC(18,15), /* Bottom Right Z of bounding box */
PRIMARY KEY(int_polyid)
);
CREATE GENERATOR GEN_TBL_GEOPOLY;
/* ===================
* geoPolyExt table
* Can add more metadata about a polygon(type:river, agri-status:desert,
etc )
* ===================
*/
CREATE TABLE tbl_geopoly_ext (
int_polyid NUMERIC(18,0) NOT NULL,
int_attribid INTEGER NOT NULL,
int_value NUMERIC(18,0), /* integer value storage */
flt_value NUMERIC(18,15), /* decimal value storage */
str_value VARCHAR(512), /* text value storage */
blb_value BLOB SUB_TYPE TEXT, /* Bulk storage of no specific type */
PRIMARY KEY(int_polyid, int_attribid),
FOREIGN KEY(int_polyid) REFERENCES tbl_geopoly(int_polyid),
FOREIGN KEY(int_attribid) REFERENCES tbl_geopoly(int_attribid)
);
/* ===================
* geoPolyPoints table
* The actual points of a polygon
* includes an ordering integer
* ===================
*/
CREATE TABLE tbl_geopolypoints (
int_polyid NUMERIC(18,0) NOT NULL,
int_pointid NUMERIC(18,0) NOT NULL,
int_order INTEGER default 0 NOT NULL,
PRIMARY KEY(int_polyid,int_pointid),
FOREIGN KEY(int_polyid) REFERENCES tbl_geopoly(int_polyid),
FOREIGN KEY(int_pointid) REFERENCES tbl_geopoint(int_pointid)
);
Finds polygon in a 2d viewport (0>x>10, 0>y>10):
select gPoly.int_polyid from tbl_geopoly gPoly
JOIN tbl_geopolypoint gPolyPoint
ON gPoly.int_polyid = gPolyPoint.int_polyid
JOIN tbl_geopoint gPoint
ON gPolyPoint.int_pointid = tbl_geopoint.int_pointid
WHERE
gPoint.flt_x between '0' and '10' AND gPoint.flt_y between '0' and '10';
You can then write stored procedures to test if a point is inside a
polygon, using standard graphics approaches (e.g. scribe an imaginary line
to the right, and count how many times it intersects with a polygon
edge(calculated via the gradient of a slope at the imaginary line's y
value)).
Have fun!
Nige.
-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com]On Behalf Of bruceeglington2
Sent: Saturday, 21 October 2006 5:43 AM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Spatial extensions for Firebird
Good day
Are there spatial extensions available for Firebird. Something
similar to the Geometry Class in MySQL or as in PostGIS? I have found
some discussion about the need for this in 2004 but nothing since.
Bruce
[Non-text portions of this message have been removed]