This can be done quite easy in SQL
All the below examples can be tested directly on
http://postgisonline.org/map.php. Just paste the query and press Map1
SELECT GENERATE_SERIES(FLOOR(ST_YMin(the_polygon))::int , CEILING(ST_YMax(the_polygon))::int,200) y_value, ST_XMin(the_polygon) x_min, ST_XMax(the_polygon) x_max from
(SELECT the_geom AS the_polygon FROM lakes) l
Next step is to build lines from those coordinates and and use ST_Intersection to only get the parts of the lines intersecting the polygon:
SELECT ST_Intersection(the_geom, the_polygon) AS the_geom FROM
(SELECT the_polygon, ST_Setsrid(ST_MakeLine(ST_MakePoint(x_min, y_value),ST_MakePoint(x_max, y_value) ), ST_Srid(the_polygon)) AS the_geom FROM
(SELECT the_polygon, GENERATE_SERIES(FLOOR(ST_YMin(the_polygon))::int , CEILING(ST_YMax(the_polygon))::int,200) y_value, ST_XMin(the_polygon) x_min, ST_XMax(the_polygon) x_max from
(SELECT the_geom AS the_polygon FROM lakes) l
)c
) lines
Then, at last we can just sum all the lengths. So what you have got is a query looking like this doing the whole operation:
SELECT SUM(ST_Length(the_geom)) FROM
(SELECT ST_Intersection(the_geom, the_polygon) AS the_geom FROM
(SELECT the_polygon, ST_Setsrid(ST_MakeLine(ST_MakePoint(x_min, y_value),ST_MakePoint(x_max, y_value) ), ST_Srid(the_polygon)) AS the_geom FROM
(SELECT the_polygon, GENERATE_SERIES(FLOOR(ST_YMin(the_polygon))::int , CEILING(ST_YMax(the_polygon))::int,200) y_value, ST_XMin(the_polygon) x_min, ST_XMax(the_polygon) x_max from
(SELECT the_geom AS the_polygon FROM lakes) l
)c
) lines
) intersection_lines
edit
This was the length part of your problem mentioned in the end of the question. To count the number of lines is no problem of course. Then just use count(*) on the top row.
HTH
Nicklas