From: <phi...@us...> - 2014-08-07 21:29:15
|
Revision: 13138 http://sourceforge.net/p/plplot/code/13138 Author: philrosenberg Date: 2014-08-07 21:29:02 +0000 (Thu, 07 Aug 2014) Log Message: ----------- Added new mapping functionality for shapefiles. Added the functions plmapline, plmapstring, plmaptex, plmapfill, which will perform appropriate drawing of the data in the shapefile, they also allow filtering which items in the shapefile are drawn. The original plmap function is left intact. The new functions are currently available from C and C++. Modified Paths: -------------- trunk/bindings/c++/plstream.cc trunk/bindings/c++/plstream.h trunk/examples/c/x19c.c trunk/examples/c++/x19.cc trunk/include/plplot.h trunk/src/plmap.c Added Paths: ----------- trunk/data/ss/ trunk/data/ss/os_open_conditions.txt trunk/data/ss/ss64ne_Building_Area.dbf trunk/data/ss/ss64ne_Building_Area.prj trunk/data/ss/ss64ne_Building_Area.shp trunk/data/ss/ss64ne_Building_Area.shx trunk/data/ss/ss64ne_General_Text.dbf trunk/data/ss/ss64ne_General_Text.prj trunk/data/ss/ss64ne_General_Text.shp trunk/data/ss/ss64ne_General_Text.shx trunk/data/ss/ss64ne_Height_Contours.dbf trunk/data/ss/ss64ne_Height_Contours.prj trunk/data/ss/ss64ne_Height_Contours.shp trunk/data/ss/ss64ne_Height_Contours.shx trunk/data/ss/ss64ne_Landform_Area.dbf trunk/data/ss/ss64ne_Landform_Area.prj trunk/data/ss/ss64ne_Landform_Area.shp trunk/data/ss/ss64ne_Landform_Area.shx trunk/data/ss/ss64ne_Landform_Line.dbf trunk/data/ss/ss64ne_Landform_Line.prj trunk/data/ss/ss64ne_Landform_Line.shp trunk/data/ss/ss64ne_Landform_Line.shx trunk/data/ss/ss64ne_Road_Centreline.dbf trunk/data/ss/ss64ne_Road_Centreline.prj trunk/data/ss/ss64ne_Road_Centreline.shp trunk/data/ss/ss64ne_Road_Centreline.shx trunk/data/ss/ss64ne_Water_Area.dbf trunk/data/ss/ss64ne_Water_Area.prj trunk/data/ss/ss64ne_Water_Area.shp trunk/data/ss/ss64ne_Water_Area.shx trunk/data/ss/ss64ne_Water_Line.dbf trunk/data/ss/ss64ne_Water_Line.prj trunk/data/ss/ss64ne_Water_Line.shp trunk/data/ss/ss64ne_Water_Line.shx Modified: trunk/bindings/c++/plstream.cc =================================================================== --- trunk/bindings/c++/plstream.cc 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/bindings/c++/plstream.cc 2014-08-07 21:29:02 UTC (rev 13138) @@ -1069,7 +1069,7 @@ pllsty( lin ); } -// plot continental outline in world coordinates +// Plot continental outline in world coordinates void plstream::map( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, PLFLT minlong, PLFLT maxlong, @@ -1080,6 +1080,52 @@ plmap( mapform, type, minlong, maxlong, minlat, maxlat ); } +// Plot map lines + +void plstream::mapline( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries) +{ + set_stream(); + + plmapline( mapform, type, minlong, maxlong, minlat, maxlat, plotentries, nplotentries ); +} + +// Plot map points + +void plstream::mapstring( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, const char *string, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries) +{ + set_stream(); + + plmapstring( mapform, type, string, minlong, maxlong, minlat, maxlat, plotentries, nplotentries ); +} + +// Plot map text + +void plstream::maptex( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT dx, PLFLT dy, PLFLT just, const char *text, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int plotentry) +{ + set_stream(); + + plmaptex( mapform, type, dx, dy, just, text, minlong, maxlong, minlat, maxlat, plotentry ); +} + +// Plot map fills + +void plstream::mapfill( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, + PLFLT maxlat, int* plotentries, int nplotentries) +{ + set_stream(); + + plmapfill( mapform, type, minlong, maxlong, minlat, maxlat, plotentries, nplotentries ); +} + // Plot the latitudes and longitudes on the background. void plstream::meridians( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), Modified: trunk/bindings/c++/plstream.h =================================================================== --- trunk/bindings/c++/plstream.h 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/bindings/c++/plstream.h 2014-08-07 21:29:02 UTC (rev 13138) @@ -468,11 +468,37 @@ void lsty( PLINT lin ); -// plot continental outline in world coordinates +// Plot continental outline in world coordinates void map( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); +// Plot map lines + + void mapline( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries); + +// Plot map points + + void mapstring( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, const char *string, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries); + +// Plot map text + + void maptex( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT dx, PLFLT dy, PLFLT just, const char *text, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int plotentry); + +// Plot map fills + + void mapfill( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, + PLFLT maxlat, int* plotentries, int nplotentries); + // Plot the latitudes and longitudes on the background. void meridians( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), Added: trunk/data/ss/os_open_conditions.txt =================================================================== --- trunk/data/ss/os_open_conditions.txt (rev 0) +++ trunk/data/ss/os_open_conditions.txt 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +Your use of OS OpenData is subject to the terms at http://www.ordnancesurvey.co.uk/oswebsite/opendata/docs/os-opendata-licence.pdf Added: trunk/data/ss/ss64ne_Building_Area.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Building_Area.dbf =================================================================== --- trunk/data/ss/ss64ne_Building_Area.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Building_Area.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Building_Area.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Building_Area.prj =================================================================== --- trunk/data/ss/ss64ne_Building_Area.prj (rev 0) +++ trunk/data/ss/ss64ne_Building_Area.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Building_Area.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Building_Area.shp =================================================================== --- trunk/data/ss/ss64ne_Building_Area.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Building_Area.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Building_Area.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Building_Area.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Building_Area.shx =================================================================== --- trunk/data/ss/ss64ne_Building_Area.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Building_Area.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Building_Area.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_General_Text.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_General_Text.dbf =================================================================== --- trunk/data/ss/ss64ne_General_Text.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_General_Text.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_General_Text.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_General_Text.prj =================================================================== --- trunk/data/ss/ss64ne_General_Text.prj (rev 0) +++ trunk/data/ss/ss64ne_General_Text.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_General_Text.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_General_Text.shp =================================================================== --- trunk/data/ss/ss64ne_General_Text.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_General_Text.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_General_Text.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_General_Text.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_General_Text.shx =================================================================== --- trunk/data/ss/ss64ne_General_Text.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_General_Text.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_General_Text.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Height_Contours.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Height_Contours.dbf =================================================================== --- trunk/data/ss/ss64ne_Height_Contours.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Height_Contours.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Height_Contours.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Height_Contours.prj =================================================================== --- trunk/data/ss/ss64ne_Height_Contours.prj (rev 0) +++ trunk/data/ss/ss64ne_Height_Contours.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Height_Contours.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Height_Contours.shp =================================================================== --- trunk/data/ss/ss64ne_Height_Contours.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Height_Contours.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Height_Contours.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Height_Contours.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Height_Contours.shx =================================================================== --- trunk/data/ss/ss64ne_Height_Contours.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Height_Contours.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Height_Contours.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Area.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Area.dbf =================================================================== --- trunk/data/ss/ss64ne_Landform_Area.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Area.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Area.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Area.prj =================================================================== --- trunk/data/ss/ss64ne_Landform_Area.prj (rev 0) +++ trunk/data/ss/ss64ne_Landform_Area.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Landform_Area.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Area.shp =================================================================== --- trunk/data/ss/ss64ne_Landform_Area.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Area.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Area.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Area.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Area.shx =================================================================== --- trunk/data/ss/ss64ne_Landform_Area.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Area.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Area.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Line.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Line.dbf =================================================================== --- trunk/data/ss/ss64ne_Landform_Line.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Line.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Line.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Line.prj =================================================================== --- trunk/data/ss/ss64ne_Landform_Line.prj (rev 0) +++ trunk/data/ss/ss64ne_Landform_Line.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Landform_Line.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Line.shp =================================================================== --- trunk/data/ss/ss64ne_Landform_Line.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Line.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Line.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Landform_Line.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Landform_Line.shx =================================================================== --- trunk/data/ss/ss64ne_Landform_Line.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Landform_Line.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Landform_Line.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Road_Centreline.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Road_Centreline.dbf =================================================================== --- trunk/data/ss/ss64ne_Road_Centreline.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Road_Centreline.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Road_Centreline.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Road_Centreline.prj =================================================================== --- trunk/data/ss/ss64ne_Road_Centreline.prj (rev 0) +++ trunk/data/ss/ss64ne_Road_Centreline.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Road_Centreline.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Road_Centreline.shp =================================================================== --- trunk/data/ss/ss64ne_Road_Centreline.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Road_Centreline.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Road_Centreline.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Road_Centreline.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Road_Centreline.shx =================================================================== --- trunk/data/ss/ss64ne_Road_Centreline.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Road_Centreline.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Road_Centreline.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Area.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Area.dbf =================================================================== --- trunk/data/ss/ss64ne_Water_Area.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Area.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Area.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Area.prj =================================================================== --- trunk/data/ss/ss64ne_Water_Area.prj (rev 0) +++ trunk/data/ss/ss64ne_Water_Area.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Water_Area.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Area.shp =================================================================== --- trunk/data/ss/ss64ne_Water_Area.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Area.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Area.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Area.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Area.shx =================================================================== --- trunk/data/ss/ss64ne_Water_Area.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Area.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Area.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Line.dbf =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Line.dbf =================================================================== --- trunk/data/ss/ss64ne_Water_Line.dbf 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Line.dbf 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Line.dbf ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Line.prj =================================================================== --- trunk/data/ss/ss64ne_Water_Line.prj (rev 0) +++ trunk/data/ss/ss64ne_Water_Line.prj 2014-08-07 21:29:02 UTC (rev 13138) @@ -0,0 +1 @@ +PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]] \ No newline at end of file Added: trunk/data/ss/ss64ne_Water_Line.shp =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Line.shp =================================================================== --- trunk/data/ss/ss64ne_Water_Line.shp 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Line.shp 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Line.shp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/data/ss/ss64ne_Water_Line.shx =================================================================== (Binary files differ) Index: trunk/data/ss/ss64ne_Water_Line.shx =================================================================== --- trunk/data/ss/ss64ne_Water_Line.shx 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/data/ss/ss64ne_Water_Line.shx 2014-08-07 21:29:02 UTC (rev 13138) Property changes on: trunk/data/ss/ss64ne_Water_Line.shx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Modified: trunk/examples/c/x19c.c =================================================================== --- trunk/examples/c/x19c.c 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/examples/c/x19c.c 2014-08-07 21:29:02 UTC (rev 13138) @@ -125,6 +125,17 @@ { PLFLT minx, maxx, miny, maxy; PLFLT x, y; + //variables for the shapelib example + const PLINT nbeachareas = 2; + PLINT beachareas[] = { 23, 24 }; + const PLINT nwoodlandareas = 94; + PLINT woodlandareas[94]; + const PLINT nshingleareas = 22; + PLINT shingleareas[]={ 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 }; + const PLINT ncragareas = 2024; + PLINT cragareas[2024]; + PLINT majorroads[]={ 33, 48, 71, 83, 89, 90, 101, 102, 111 }; + int i; // Parse and process command line arguments @@ -201,6 +212,112 @@ // For C, this is how the global transform is cleared plstransform( NULL, NULL ); + // An example using shapefiles. The shapefiles used are from Ordnance Survey, UK. + // These were chosen because they provide shapefiles for small grid boxes which + // are easilly manageable for this demo. + + pllsty( 1 ); + + + minx=240570; + maxx=621109; + miny=87822; + maxy=722770; + plscol0(0, 255, 255, 255 ); + plscol0(1, 0, 0, 0 ); + plscol0(2, 150, 150, 150 ); + plscol0(3, 0, 50, 200 ); + plscol0(4, 50, 50, 50 ); + plscol0(5, 150, 0, 0 ); + plscol0(6, 100, 100, 255 ); + + + minx=265000; + maxx=270000; + miny=145000; + maxy=150000; + plscol0( 0, 255, 255, 255 ); //white + plscol0( 1, 0, 0, 0 ); //black + plscol0( 2, 255, 200, 0 ); //yelow for sand + plscol0( 3, 60, 230, 60 ); // green for woodland + plscol0( 4, 210, 120, 60 ); //brown for contours + plscol0( 5, 150, 0, 0 ); //red for major roads + plscol0( 6, 180, 180, 255 ); //pale blue for water + plscol0( 7, 100, 100, 100 ); //pale grey for shingle or boulders + plscol0( 8, 100, 100, 100 ); //dark grey for custom polygons - generally crags + + + plcol0(1); + plenv( minx, maxx, miny, maxy, 1, -1 ); + pllab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" ); + + + //Beach + plcol0( 2 ); + plmapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas, nbeachareas ); + + //woodland + plcol0( 3 ); + for( i=0; i < nwoodlandareas; ++ i ) + woodlandareas[i] = i + 218; + plmapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, woodlandareas, nwoodlandareas ); + + //shingle or boulders + plcol0( 7 ); + plmapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas, nshingleareas ); + + //crags + plcol0( 8 ); + for( i=0; i < ncragareas; ++ i ) + cragareas[i] = i + 325; + plmapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, cragareas, ncragareas ); + + //draw contours, we need to separate contours from high/low coastline + //draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy ); + plcol0( 4 ); + plmapline(NULL, "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, NULL, 0 ); + + //draw the sea and surface water + plwidth( 0.0 ); + plcol0(6); + plmapfill(NULL, "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, NULL, 0 ); + plwidth( 2.0 ); + plmapfill(NULL, "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, NULL, 0 ); + + //draw the roads, first with black and then thinner with colour to give an + //an outlined appearance + plwidth( 5.0 ); + plcol0( 1 ); + plmapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); + plwidth( 3.0 ); + plcol0( 0 ); + plmapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); + plcol0( 5 ); + plmapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads, 9 ); + + //draw buildings + plwidth( 1.0 ); + plcol0( 1 ); + plmapfill(NULL, "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, NULL, 0 ); + + //labels + plsfci( 0x80000100 ); + plschr(0, 0.8); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202); + plschr(0,0.7); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211); + plschr(0, 0.6); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61); + plmaptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62); + plend(); exit( 0 ); } Modified: trunk/examples/c++/x19.cc =================================================================== --- trunk/examples/c++/x19.cc 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/examples/c++/x19.cc 2014-08-07 21:29:02 UTC (rev 13138) @@ -144,10 +144,33 @@ } } +//a function to draw the contour data and coastline from the example shapefiles +void +draw_contours(plstream *pls, const char *file, PLINT ncontours, PLINT nwater, PLINT colourcontours, PLINT colourwater, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy) +{ + PLINT i; + PLINT *contours = ( PLINT* ) malloc ( ncontours * sizeof( PLINT ) ); + PLINT *water = ( PLINT* ) malloc ( nwater * sizeof( PLINT ) ); + for( i = 0; i < ncontours; ++i ) + contours[i] = i; + for( i = 0; i < nwater; ++i ) + water[i] = i + ncontours; + + pls->col0(colourcontours); + pls->mapline( NULL, file, minx, maxx, miny, maxy, contours, ncontours ); + pls->col0(colourwater); + pls->mapline( NULL, file, minx, maxx, miny, maxy, water, nwater ); + + free( contours ); + free( water ); +} + + x19::x19( int argc, const char ** argv ) { PLFLT minx, maxx, miny, maxy; + PLINT i; // plplot initialization @@ -166,6 +189,7 @@ // Cartesian plots // Most of world + minx = -170; maxx = minx + 360; @@ -225,6 +249,122 @@ // For C, this is how the global transform is cleared pls->stransform( NULL, NULL ); + + // An example using shapefiles. The shapefiles used are from Ordnance Survey, UK. + // These were chosen because they provide shapefiles for small grid boxes which + // are easilly manageable for this demo. + + pls->lsty( 1 ); + + + minx=240570; + maxx=621109; + miny=87822; + maxy=722770; + pls->scol0(0, 255, 255, 255 ); + pls->scol0(1, 0, 0, 0 ); + pls->scol0(2, 150, 150, 150 ); + pls->scol0(3, 0, 50, 200 ); + pls->scol0(4, 50, 50, 50 ); + pls->scol0(5, 150, 0, 0 ); + pls->scol0(6, 100, 100, 255 ); + + + minx=265000; + maxx=270000; + miny=145000; + maxy=150000; + pls->scol0( 0, 255, 255, 255 ); //white + pls->scol0( 1, 0, 0, 0 ); //black + pls->scol0( 2, 255, 200, 0 ); //yelow for sand + pls->scol0( 3, 60, 230, 60 ); // green for woodland + pls->scol0( 4, 210, 120, 60 ); //brown for contours + pls->scol0( 5, 150, 0, 0 ); //red for major roads + pls->scol0( 6, 180, 180, 255 ); //pale blue for water + pls->scol0( 7, 100, 100, 100 ); //pale grey for shingle or boulders + pls->scol0( 8, 100, 100, 100 ); //dark grey for custom polygons - generally crags + + + pls->col0(1); + pls->env( minx, maxx, miny, maxy, 1, -1 ); + pls->lab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" ); + + + //Beach + pls->col0( 2 ); + const PLINT nbeachareas = 2; + PLINT beachareas[] = { 23, 24 }; + pls->mapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas, nbeachareas ); + + //woodland + pls->col0( 3 ); + const PLINT nwoodlandareas = 94; + PLINT woodlandareas[nwoodlandareas]; + for( i=0; i < nwoodlandareas; ++ i ) + woodlandareas[i] = i + 218; + pls->mapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, woodlandareas, nwoodlandareas ); + + //shingle or boulders + pls->col0( 7 ); + const PLINT nshingleareas = 22; + PLINT shingleareas[]={ 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 }; + pls->mapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas, nshingleareas ); + + //crags + pls->col0( 8 ); + const PLINT ncragareas = 2024; + PLINT cragareas[ncragareas]; + for( i=0; i < ncragareas; ++ i ) + cragareas[i] = i + 325; + pls->mapfill(NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, cragareas, ncragareas ); + + //draw contours, we need to separate contours from high/low coastline + //draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy ); + pls->col0( 4 ); + pls->mapline(NULL, "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, NULL, 0 ); + + //draw the sea and surface water + pls->width( 0.0 ); + pls->col0(6); + pls->mapfill(NULL, "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, NULL, 0 ); + pls->width( 2.0 ); + pls->mapfill(NULL, "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, NULL, 0 ); + + //draw the roads, first with black and then thinner with colour to give an + //an outlined appearance + pls->width( 5.0 ); + pls->col0( 1 ); + pls->mapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); + pls->width( 3.0 ); + pls->col0( 0 ); + pls->mapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); + PLINT majorroads[]={ 33, 48, 71, 83, 89, 90, 101, 102, 111 }; + pls->col0( 5 ); + pls->mapline(NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads, 9 ); + + //draw buildings + pls->width( 1.0 ); + pls->col0( 1 ); + pls->mapfill(NULL, "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, NULL, 0 ); + + //labels + pls->sfci( 0x80000100 ); + pls->schr(0, 0.8); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202); + pls->schr(0,0.7); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211); + pls->schr(0, 0.6); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61); + pls->maptex(NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62); + delete pls; } Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/include/plplot.h 2014-08-07 21:29:02 UTC (rev 13138) @@ -660,6 +660,10 @@ #define plline3 c_plline3 #define pllsty c_pllsty #define plmap c_plmap +#define plmapline c_plmapline +#define plmapstring c_plmapstring +#define plmaptex c_plmaptex +#define plmapfill c_plmapfill #define plmeridians c_plmeridians #define plmesh c_plmesh #define plmeshc c_plmeshc @@ -1287,12 +1291,42 @@ PLDLLIMPEXP void c_pllsty( PLINT lin ); -// plot continental outline in world coordinates +// Plot continental outline in world coordinates PLDLLIMPEXP void c_plmap( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); +// Plot map outlines + +PLDLLIMPEXP void +c_plmapline( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries); + +// Plot map points + +PLDLLIMPEXP void +c_plmapstring( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, const char *string, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int* plotentries, int nplotentries); + +// Plot map text + +PLDLLIMPEXP void +c_plmaptex( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT dx, PLFLT dy, PLFLT just, const char *text, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, + int plotentry); + +// Plot map fills + +PLDLLIMPEXP void +c_plmapfill( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), + const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, + PLFLT maxlat, int* plotentries, int nplotentries); + // Plot the latitudes and longitudes on the background. PLDLLIMPEXP void Modified: trunk/src/plmap.c =================================================================== --- trunk/src/plmap.c 2014-07-11 18:32:21 UTC (rev 13137) +++ trunk/src/plmap.c 2014-08-07 21:29:02 UTC (rev 13138) @@ -51,120 +51,282 @@ #ifdef HAVE_SAHOOKS static void CustomErrors( const char *message ); -#endif +#endif //HAVE_SAHOOKS -#endif - -//-------------------------------------------------------------------------- -// void plmap(void (*mapform)(PLINT, PLFLT *, PLFLT *), const char *type, -// PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); -// -// plot continental outline in world coordinates -// -// v1.4: machine independant version -// v1.3: replaced plcontinent by plmap, added plmeridians -// v1.2: 2 arguments: mapform, type of plot -// -// mapform(PLINT n, PLFLT *x, PLFLT *y) is a routine to transform the -// coordinate longitudes and latitudes to a plot coordinate system. By -// using this transform, we can change from a longitude, latitude -// coordinate to a polar stereographic project, for example. Initially, -// x[0]..[n-1] are the longitudes and y[0]..y[n-1] are the corresponding -// latitudes. After the call to mapform(), x[] and y[] should be replaced -// by the corresponding plot coordinates. If no transform is desired, -// mapform can be replaced by NULL. -// -// type is a character string. The value of this parameter determines the -// type of background. The possible values are, -// -// "globe" continental outlines -// "usa" USA and state boundaries -// "cglobe" continental outlines and countries -// "usaglobe" USA, state boundaries and continental outlines -// alternatively the filename of a shapefile can be passed if PLplot has -// been compiled with shapelib. In this case either the base name of the -// file can be passed or the filename including the .shp or .shx suffix. -// Only the .shp and .shx files are used. -// -// minlong, maxlong are the values of the longitude on the left and right -// side of the plot, respectively. The value of minlong must be less than -// the values of maxlong, and the values of maxlong-minlong must be less -// or equal to 360. -// -// minlat, maxlat are the minimum and maximum latitudes to be plotted on -// the background. One can always use -90.0 and 90.0 as the boundary -// outside the plot window will be automatically eliminated. However, the -// program will be faster if one can reduce the size of the background -// plotted. -//-------------------------------------------------------------------------- - -#ifdef HAVE_SHAPELIB #define MAP_FILE "" #define OpenMap OpenShapeFile #define CloseMap SHPClose -#else + +#else //HAVE_SHAPELIB + #define MAP_FILE ".map" #define OpenMap plLibOpenPdfstrm #define CloseMap pdf_close #define OFFSET ( 180 * 100 ) #define SCALE 100.0 #define W_BUFSIZ ( 32 * 1024 ) -#endif +#define SHPT_ARC 1 +#define SHPT_POINT 2 +#define SHPT_POLYGON 3 +#endif //HAVE_SHAPELIB + +//redistributes the lon value onto either 0-360 or -180-180 for wrapping +//purposes. void -plmap( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, - PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ) +rebaselon( PLFLT *lon, PLFLT midlon ) { + if( *lon > midlon + 180.0 ) + *lon -= floor( ( *lon - midlon - 180.0 ) / 360.0 + 1.0 ) * 360.0; + else if( *lon < midlon - 180.0 ) + *lon += floor( ( midlon - 180.0 - *lon ) / 360.0 + 1.0 ) * 360.0; + +} + +//append a PLFLT to an array of PLFLTs. array is a pointer to the array, +//n is the current size of the array, val is the value to append. +//returns 0 for success, 1 for could not allocate new memory. If memory +//could not be allocated then the previous array remains intact +int appendflt( PLFLT **array, size_t n, PLFLT val ) +{ + size_t i; + PLFLT *temp = ( PLFLT* ) malloc( ( n + 1 ) * sizeof( PLFLT ) ); + if( !temp) + return 1; + for( i = 0; i < n; ++i ) + temp[i]=(*array)[i]; + temp[n] = val; + free ( *array ); + *array = temp; + return 0; +} + +//As for appendflt, but for an array of ints +int appendint( int **array, size_t n, int val ) +{ + size_t i; + int *temp = ( int* ) malloc( ( n + 1 ) * sizeof( int ) ); + if( !temp) + return 1; + for( i = 0; i < n; ++i ) + temp[i]=(*array)[i]; + temp[n] = val; + free ( *array ); + *array = temp; + return 0; +} + +//As for appendflt, but for an array of pointers to PLFLTs +int appendfltptr( PLFLT ***array, size_t n, PLFLT *val ) +{ + size_t i; + PLFLT **temp = ( PLFLT** ) malloc( ( n + 1 ) * sizeof( PLFLT *) ); + if( !temp) + return 1; + for(i = 0; i < n; ++i) + temp[i]=(*array)[i]; + temp[n] = val; + free ( *array ); + *array = temp; + return 0; +} + +//Check to see if the mapform wraps round longitudes. For example, a polar +// projection wraps round longitudes, but a cylindrical projection does not. +//Returns 1 if the mapform wraps or 0 if not. +char +checkwrap( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), PLFLT lon, PLFLT lat ) +{ + PLFLT x[]={lon}; + PLFLT y[]={lat}; + PLFLT resultx; + PLFLT resulty; + + if( !mapform ) + return 0; + + mapform( 1, x, y ); + resultx = x[0]; + resulty = y[0]; + x[0] = lon + 360; + y[0] = lat; + return ( ( ABS( x[0] - resultx ) < 1.0e-12 ) && ( ABS( y[0] - resulty ) < 1.0e-12 ) ); +} + +//------------------------------------------------------------------------------------- +//Actually draw the map lines points and text. +//------------------------------------------------------------------------------------- +void +drawmapdata( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), int shapetype, PLINT n, PLFLT *x, PLFLT *y, PLFLT dx, PLFLT dy, PLFLT just, const char *text ) +{ + PLINT i; + + //do the transform if needed + if ( mapform != NULL ) + ( *mapform )( n, x, y ); + + if ( shapetype == SHPT_ARC ) + plline( n, x, y ); + else if ( shapetype == SHPT_POINT ) + for ( i = 0; i < n; ++i ) + plptex( x[i], y[i], dx, dy, just, text ); + else if ( shapetype == SHPT_POLYGON ) + plfill( n, x, y ); +#ifdef HAVE_SHAPELIB + else if( shapetype == SHPT_ARCZ || shapetype == SHPT_ARCM ) + plline( n, x, y ); + else if( shapetype == SHPT_POLYGON || shapetype == SHPT_POLYGONZ || shapetype == SHPT_POLYGONM ) + plfill( n, x, y ); + else if( shapetype == SHPT_POINT || shapetype ==SHPT_POINTM || shapetype == SHPT_POINTZ ) + for ( i = 0; i < n; ++i ) + plptex( x[i], y[i], dx, dy, just, text ); +#endif //HAVE_SHAPELIB +} + + +//------------------------------------------------------------------------------------- +//This is a function called by the front end map functions to do the map drawing. Its +//parameters are: +//mapform: The transform used to convert the data in raw coordinates to x, y positions +//on the plot +//type: either one of the plplot provided lat/lon maps or the path/file name of a +//shapefile +//dx/dy: the gradient of text/symbols drawn if text is non-null +//shapetype: one of ARC, SHPT_ARCZ, SHPT_ARCM, SHPT_POLYGON, SHPT_POLYGONZ, +//SHPT_POLYGONM, SHPT_POINT, SHPT_POINTM, SHPT_POINTZ. See drawmapdata() for the +//how each type is rendered. But Basically the ARC options are lines, the POLYGON +//options are filled polygons, the POINT options are points/text. Options beginning +//SHPT will only be defined if HAVE_SHAPELIB is true +//text: The text (which can be actual text or a unicode symbol) to be drawn at +//each point +//minlong/maxlong: The min/max longitude when using a plplot provided map or x value if +//using a shapefile +//minlat/maxlat: The min/max latitude when using a plplot provided map or y value if +//using a shapefile +//plotentries: used only for shapefiles, as one shapefile contains multiple vectors +//each representing a different item (e.g. multiple boundaries, multiple height +//contours etc. plotentries is an array containing the indices of the +//entries within the shapefile that you wish to plot. if plotentries is null all +//entries are plotted +//nplotentries: the number of elements in plotentries. Ignored if plplot was not built +//with shapefile support or if plotentries is null +//------------------------------------------------------------------------------------- +void +drawmap( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), const char *type, + PLFLT dx, PLFLT dy, int shapetype, PLFLT just, const char *text, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat, int* plotentries, int nplotentries ) +{ #if defined ( HAVE_SHAPELIB ) || defined ( PL_DEPRECATED ) int i, j; - char *filename; - char *warning; - int n = 200; + char *filename = NULL; + char truncatedfilename[900]; + char warning[1024]; + int nVertices = 200; PLFLT minsectlon, maxsectlon, minsectlat, maxsectlat; - const int ncopies = 5; //must be odd - original plus copies shifted by multiples of +/- 360 - const int mid = ncopies / 2 + 1; - PLFLT **bufx = NULL, **bufy = NULL; + PLFLT *bufx = NULL, *bufy = NULL; int bufsize = 0; + int filenamelen; + PLFLT **splitx = NULL; + PLFLT **splity = NULL; + int *splitsectionlengths = NULL; + int nsplitsections; + PLFLT lastsplitpointx; + PLFLT lastsplitpointy; + PLFLT penultimatesplitpointx; + PLFLT penultimatesplitpointy; + char islatlon = 1; + #ifdef HAVE_SHAPELIB SHPHandle in; int nentries; + int entryindex=0; // Unnecessarily set nparts to quiet -O3 -Wuninitialized warnings. - int nparts = 0; + //int nparts = 0; int entrynumber = 0; int partnumber = 0; - int shapetype; double mins[4]; double maxs[4]; SHPObject *object = NULL; double *bufxraw; double *bufyraw; + char *prjfilename = NULL; + PDFstrm *prjfile; + char prjtype[]={0, 0, 0, 0, 0, 0, 0}; + int appendresult=0; #else - register PDFstrm *in; + PDFstrm *in; //PLFLT bufx[ncopies][200], bufy[ncopies][200]; unsigned char n_buff[2], buff[800]; long int t; - int k; #endif // // read map outline // - filename = malloc( strlen( type ) + strlen( MAP_FILE ) + 1 ); - strcpy( filename, type ); + + //strip the .shp extension if a shapefile has been provided and add + //the needed map file extension if we are not using shapefile + if( strstr( type, ".shp" ) ) + filenamelen=( int )( type-strstr( type, ".shp" ) ); + else + filenamelen = ( int )strlen( type ); + filename = ( char* )malloc( filenamelen + strlen( MAP_FILE ) + 1 ); + if(!filename) + { + plabort("Could not allocate memory for concatenating map filename"); + return; + } + strncpy( filename, type, filenamelen ); + filename[ filenamelen ] = '\0'; strcat( filename, MAP_FILE ); - warning = malloc( strlen( type ) + strlen( MAP_FILE ) + 50 ); + //copy the filename to a fixed length array in case it is needed for warning messages + if( strlen( filename ) < 899 ) + strcpy( truncatedfilename, filename ); + else + { + memcpy( truncatedfilename, filename, 896 ); + truncatedfilename[896] = '.'; + truncatedfilename[897] = '.'; + truncatedfilename[898] = '.'; + truncatedfilename[899] = '\0'; + } + strcpy( warning, "Could not find " ); strcat( warning, filename ); strcat( warning, " file." ); #ifdef HAVE_SHAPELIB + //Open the shp and shx file using shapelib if ( ( in = OpenShapeFile( filename ) ) == NULL ) { - plwarn( warning ); + plabort( warning ); + free(filename); return; } SHPGetInfo( in, &nentries, &shapetype, mins, maxs ); + //also check for a prj file which will tell us if the data is lat/lon or projected + //if it is projected then set ncopies to 1 - i.e. don't wrap round longitudes + prjfilename = ( char* )malloc( filenamelen + 5 ); + if(!prjfilename) + { + plabort("Could not allocate memory for generating map projection filename"); + free(filename); + return; + } + strncpy( prjfilename, type, filenamelen ); + prjfilename[ filenamelen ] = '\0'; + strcat( prjfilename, ".prj" ); + prjfile = plLibOpenPdfstrm( prjfilename ); + if ( prjfile && prjfile->file ) + { + fread( prjtype, 1, 6, prjfile->file ); + if( strcmp ( prjtype, "PROJCS" ) == 0 ) + islatlon = 0; + pdf_close( prjfile ); + } + free ( prjfilename ); + prjfilename = NULL; #else if ( ( in = plLibOpenPdfstrm( filename ) ) == NULL ) { @@ -173,61 +335,90 @@ } #endif - bufx = malloc( (size_t) ncopies * sizeof ( PLFLT* ) ); - bufy = malloc( (size_t) ncopies * sizeof ( PLFLT* ) ); - for ( i = 0; i < ncopies; i++ ) - { - bufx[i] = NULL; - bufy[i] = NULL; - } + bufx = NULL; + bufy = NULL; for (;; ) { #ifdef HAVE_SHAPELIB + //each object in the shapefile is split into parts. + //If we are need to plot the first part of an object then read in a new object + //and check how many parts it has. Otherwise use the object->panPartStart vector + //to check the offset of this part and the next part and allocate memory. Copy + //the data to this memory converting it to PLFLT and draw it. + //finally increment the part number or if we have finished with the object reset the + //part numberand increment the object. + //break condition if we've reached the end of the file - if ( entrynumber == nentries ) + if ( ( !plotentries && ( entrynumber == nentries ) ) || ( plotentries && ( entryindex == nplotentries ) ) ) break; + //if partnumber == 0 then we need to load the next object if ( partnumber == 0 ) { - object = SHPReadObject( in, entrynumber ); - nparts = object->nParts; + if( plotentries ) + object = SHPReadObject( in, plotentries[entryindex] ); + else + object = SHPReadObject( in, entrynumber ); } + //if the object could not be read, increment the object index to read and + //return to the top of the loop to try the next object. + if ( object == NULL ) + { + entrynumber++; + entryindex++; + partnumber = 0; + continue; + } //work out how many points are in the current part - if ( partnumber == ( nparts - 1 ) ) - n = object->nVertices - object->panPartStart[partnumber]; + if( object->nParts == 0 ) + nVertices = object->nVertices; //if object->nParts==0, we can still have 1 vertex. A bit odd but it's the way it goes + else if ( partnumber == ( object->nParts - 1 ) ) + nVertices = object->nVertices - object->panPartStart[partnumber];//panPartStart holds the offset for each part else - n = object->panPartStart[partnumber + 1] - object->panPartStart[partnumber]; + nVertices = object->panPartStart[partnumber + 1] - object->panPartStart[partnumber];//panPartStart holds the offset for each part #endif //allocate memory for the data - if ( n > bufsize ) + if ( nVertices > bufsize ) { - bufsize = n; - for ( i = 0; i < ncopies; i++ ) - { - if ( bufx[i] ) - free( bufx[i] ); - if ( bufy[i] ) - free( bufy[i] ); - bufx[i] = malloc( (size_t) bufsize * sizeof ( double ) ); - bufy[i] = malloc( (size_t) bufsize * sizeof ( double ) ); - } + bufsize = nVertices; + free( bufx ); + free( bufy ); + bufx = (PLFLT*)malloc( (size_t) bufsize * sizeof ( PLFLT ) ); + bufy = (PLFLT*)malloc( (size_t) bufsize * sizeof ( PLFLT ) ); + if(!bufx || ! bufy) + { + plabort("Could not allocate memory for map data"); + free(filename); + free (bufx); + free (bufy); + return; + } } #ifdef HAVE_SHAPELIB //point the plot buffer to the correct starting vertex - //and copy it to the PLFLT arrays - bufxraw = object->padfX + object->panPartStart[partnumber]; - bufyraw = object->padfY + object->panPartStart[partnumber]; - for ( i = 0; i < n; i++ ) + //and copy it to the PLFLT arrays. If we had object->nParts == 0 + //then panPartStart will be NULL + if(object->nParts>0) + { + bufxraw = object->padfX + object->panPartStart[partnumber]; + bufyraw = object->padfY + object->panPartStart[partnumber]; + } + else + { + bufxraw = object->padfX; + bufyraw = object->padfY; + } + + for ( i = 0; i < nVertices; i++ ) { - bufx[mid][i] = (PLFLT) bufxraw[i]; - for ( j = 0; j < ncopies; j++ ) - bufy[j][i] = (PLFLT) bufyraw[i]; + bufx[i] = (PLFLT) bufxraw[i]; + bufy[i] = (PLFLT) bufyraw[i]; } - //set the minlat/lon of the object + //set the min x/y of the object minsectlon = object->dfXMin; maxsectlon = object->dfXMax; minsectlat = object->dfYMin; @@ -235,36 +426,40 @@ //increment the partnumber or if we've reached the end of //an entry increment the entrynumber and set partnumber to 0 - if ( partnumber == nparts - 1 ) + if ( partnumber == object->nParts - 1 || object->nParts == 0 ) { entrynumber++; + entryindex++; partnumber = 0; + SHPDestroyObject( object ); + object=NULL; } else partnumber++; + + if (nVertices==0) + continue; #else // read in # points in segment if ( pdf_rdx( n_buff, (long) sizeof ( unsigned char ) * 2, in ) == 0 ) break; - n = ( n_buff[0] << 8 ) + n_buff[1]; - if ( n == 0 ) + nVertices = ( n_buff[0] << 8 ) + n_buff[1]; + if ( nVertices == 0 ) break; - pdf_rdx( buff, (long) sizeof ( unsigned char ) * 4 * n, in ); - if ( n == 1 ) + pdf_rdx( buff, (long) sizeof ( unsigned char ) * 4 * nVertices, in ); + if ( nVertices == 1 ) continue; - for ( j = i = 0; i < n; i++, j += 2 ) + for ( j = i = 0; i < nVertices; i++, j += 2 ) { t = ( buff[j] << 8 ) + buff[j + 1]; - bufx[mid][i] = ( (PLFLT) t - OFFSET ) / SCALE; + bufx[i] = ( (PLFLT) t - OFFSET ) / SCALE; } - for ( i = 0; i < n; i++, j += 2 ) + for ( i = 0; i < nVertices; i++, j += 2 ) { t = ( buff[j] << 8 ) + buff[j + 1]; - bufy[0][i] = ( (PLFLT) t - OFFSET ) / SCALE; - for ( k = 1; k < ncopies; k++ ) - bufy[k][i] = bufy[0][i]; + bufy[i] = ( (PLFLT) t - OFFSET ) / SCALE; } //set the min/max section lat/lon with extreme values //to be overwritten later @@ -274,63 +469,165 @@ maxsectlat = -1000.; #endif - //two obvious issues exist here with plotting longitudes: - // - //1) wraparound causing lines which go the wrong way round - // the globe - //2) some people plot lon from 0-360 deg, others from -180 - +180 - // - //we can cure these problems by conditionally adding/subtracting - //360 degrees to each data point in order to ensure that the - //distance between adgacent points is always less than 180 - //degrees, then plotting up to 2 out of 5 copies of the data - //each separated by 360 degrees. - for ( i = 0; i < n - 1; i++ ) - { - if ( bufx[mid][i] - bufx[mid][i + 1] > 180. ) - bufx[mid][i + 1] += 360.; - else if ( bufx[mid][i] - bufx[mid][i + 1] < -180. ) - bufx[mid][i + 1] -= 360.; - } - for ( i = 0; i < n; i++... [truncated message content] |