/* Maybe this helps:
Azimuth - pi/2 is the outward facing orientation of the sides of a RHR polygon:
Here is a PostGIS example, you can create the bldg117862 table using the statement at the end.
The SRID is EPSG 2271 (PA StatePlane North Feet) and the geometry is a Multipolygon.
To visualize in ArcGIS 10, paste query/subqueries into a Query Layer connection to postgis after creating the table bldg117862 .*/
--===START OF QUERY===
/*Outer query provides orientation of outward orthogonals, and creates outward orthogonal lines of equal lengths as those of the sides
from the sides' midpoint.
Dominant facing direction(s) will be the sum of the length, grouped by orientation, in descending order */
SELECT line_id as side_id, length, degrees(orthoaz)as orientation,st_makeline(st_setsrid(st_line_interpolate_point(geom,.5),2271),
st_setsrid(st_makepoint(st_x(st_line_interpolate_point(geom,.5))+ (length * (sin(orthoaz))),
st_y(st_line_interpolate_point(geom,.5))+ (length * (cos(orthoaz)))),2271)) as geom
from
--next outer subquery makes lines from sides' point pairs, calculate the azimuth (orthoaz) of outward orthogonal for each segment
(
SELECT bldg2009gid, line_id, st_length(st_makeline(startpoint,endpoint))::numeric(10,2) as length,
azimuth(startpoint,endpoint),azimuth(startpoint,endpoint) - pi()/2 as orthoaz, st_makeline(startpoint,endpoint) as geom
from
/*innermost subquery - use generate_series() to decompose building polygons into sides' startpoint/endpoint point pairs -
note1 - force right-hand-rule to ensure common orientation of all polygon sides
note2 - example uses multipolygon, for polygon the geometryn() can be removed */
(
SELECT generate_series(1, npoints(exteriorring(geometryn(st_forceRHR(geom),1)))-1) as line_id,gid as bldg2009gid,
pointn(exteriorring(geometryn(st_forceRHR(geom),1)) ,generate_series(1, npoints(exteriorring(geometryn(st_forceRHR(geom),1)))-1)) as startpoint,
pointn(exteriorring(geometryn(st_forceRHR(geom),1)) ,generate_series(2, npoints(exteriorring(geometryn(st_forceRHR(geom),1))))) as endpoint
from bldg117862
) as t1
) as t2
--===END OF QUERY===
-- the bldg117862 table create/insert statements
SET STANDARD_CONFORMING_STRINGS TO ON;
SELECT DropGeometryColumn('','bldg117862','geom');
DROP TABLE "bldg117862";
BEGIN;
CREATE TABLE "bldg117862" (gid serial PRIMARY KEY,
"motherpin" varchar(14),
"taxpin" varchar(14),
"status" varchar(15),
"area" numeric,
"prev_area" numeric,
"pct_change" numeric,
"picture" varchar(133),
"mappage" varchar(6),
"sref_gid" int4,
"e_address" varchar(19),
"a_address" varchar(19),
"perim" numeric,
"card" int4,
"a_addnum" int4,
"e_street" varchar(50),
"a_street" varchar(50),
"e_hsnum" varchar(10));
SELECT AddGeometryColumn('','bldg117862','geom','2271','MULTIPOLYGON',2);
INSERT INTO "bldg117862" ("motherpin","taxpin","status","area","prev_area","pct_change","picture","mappage","sref_gid","e_address","a_address","perim","card","a_addnum","e_street","a_street","e_hsnum",geom) VALUES ('33108480001346',NULL,'Changed','2445.59000000','2139.51000000','14.3100000000','http://www.eriecountygov.org/government/assessment/parcelimages.aspx?parcelid=33108480001346" target="_blank">Image Page','33-108','99040','4622 MCCLELLAND AVE','4622 MCCLELLAND AVE','233.37','1','4622','MCCLELLAND AVE',NULL,'4622','0106000020DF080000010000000103000020DF080000010000000B0000008C721D6C98AC34415E2C5BB9D3E32541AE56DE17BEAC34410613E5A0A0E325411AB6C794AEAC3441BA392FE372E32541C89C38429DAC3441643857628AE325418C299A9095AC3441F66C29B573E32541983F02087EAC34413080AA9F93E325419BAC3C0A86AC3441AC1F3B3DABE32541803A40B974AC3441E8CF3DB9C2E325413E3758C186AC3441D0AAB0E7F7E325410AAAA5429BAC3441BA971217DCE325418C721D6C98AC34415E2C5BB9D3E32541');
CREATE INDEX "bldg117862_geom_gist" ON "bldg117862" using gist ("geom" gist_geometry_ops);
END;