56 #define OpenMap OpenShapeFile 57 #define CloseMap SHPClose 64 if ( *lon > midlon + 180.0 )
65 *lon -= floor( ( *lon - midlon - 180.0 ) / 360.0 + 1.0 ) * 360.0;
66 else if ( *lon < midlon - 180.0 )
67 *lon += floor( ( midlon - 180.0 - *lon ) / 360.0 + 1.0 ) * 360.0;
91 if ( ( shapetype == SHPT_POLYGON || shapetype == SHPT_POLYGONZ || shapetype == SHPT_POLYGONM ) && x[0] != x[n - 1] )
95 if ( x[0] != x[n - 1] )
101 PLINT nExtraPoints =
MAX( 501, n + 1 );
107 if ( x[n - 1] > x[0] )
112 newX = malloc( ( n + nExtraPoints ) *
sizeof (
double ) );
113 newY = malloc( ( n + nExtraPoints ) *
sizeof (
double ) );
114 if ( !newX || !newY )
118 plabort(
"Could not allocate memory for adding pole points to a map polygon." );
121 memcpy( newX, x, n *
sizeof (
double ) );
122 memcpy( newY, y, n *
sizeof (
double ) );
124 lonInterval = ( x[0] - x[n - 1] ) / (
double) ( nExtraPoints - 2 );
126 for ( i = 0; i < nExtraPoints - 1; ++i )
128 newX[n + i] = x[n - 1] + i * lonInterval;
129 newY[n + i] = poleLat;
131 newX[n + nExtraPoints - 1] = x[0];
132 newY[n + nExtraPoints - 1] = y[0];
137 fltX = malloc( ( n + nExtraPoints ) *
sizeof (
PLFLT ) );
138 fltX = malloc( ( n + nExtraPoints ) *
sizeof (
PLFLT ) );
139 if ( !fltX || !fltY )
145 plabort(
"Could not allocate memory converting map date to floats." );
148 for ( i = 0; i < n + nExtraPoints; ++i )
150 fltX[i] = (
PLFLT) newX[i];
151 fltY[i] = (
PLFLT) newY[i];
156 if ( mapform != NULL )
157 (*mapform)( n + nExtraPoints, renderX, renderY );
158 plfill( n + nExtraPoints, renderX, renderY );
172 if ( mapform != NULL )
173 (*mapform)( n, x, y );
189 fltX = malloc( n *
sizeof (
PLFLT ) );
190 fltX = malloc( n *
sizeof (
PLFLT ) );
191 if ( !fltX || !fltY )
195 plabort(
"Could not allocate memory converting map date to floats." );
198 for ( i = 0; i < n; ++i )
200 fltX[i] = (
PLFLT) x[i];
201 fltY[i] = (
PLFLT) y[i];
208 if ( mapform != NULL )
209 ( *mapform )( n, renderX, renderY );
212 if ( shapetype == SHPT_ARC )
213 plline( n, renderX, renderY );
214 else if ( shapetype == SHPT_POINT )
215 for ( i = 0; i < n; ++i )
216 plptex( renderX[i], renderY[i], dx, dy, just, text );
217 else if ( shapetype == SHPT_ARCZ || shapetype == SHPT_ARCM )
218 plline( n, renderX, renderY );
219 else if ( shapetype == SHPT_POINTM || shapetype == SHPT_POINTZ )
220 for ( i = 0; i < n; ++i )
221 plptex( renderX[i], renderY[i], dx, dy, just, text );
222 else if ( shapetype == SHPT_POLYGON || shapetype == SHPT_POLYGONZ || shapetype == SHPT_POLYGONM )
223 plfill( n, renderX, renderY );
224 else if ( shapetype == SHPT_NULL )
227 plabort(
"Unknown render type passed in to drawmapdata(). PLplot can render shapefile arcs, points and polygons (including z and m variants)." );
269 char *filename = NULL;
272 double minsectlon, maxsectlon, minsectlat, maxsectlat;
277 int appendresult = 0;
285 SHPObject *
object = NULL;
288 char *prjfilename = NULL;
290 char prjtype[] = { 0, 0, 0, 0, 0, 0, 0 };
300 if ( strstr( name,
".shp" ) )
301 filenamelen = ( strlen( name ) - 4 );
303 filenamelen = strlen( name );
304 filename = (
char *) malloc( filenamelen + 1 );
307 plabort(
"Could not allocate memory for map filename root" );
310 strncpy( filename, name, filenamelen );
311 filename[ filenamelen ] =
'\0';
314 if ( ( in = OpenShapeFile( filename ) ) == NULL )
316 strcpy( warning,
"Could not find " );
317 strcat( warning, filename );
318 strcat( warning,
" file." );
323 SHPGetInfo( in, &nentries, &fileShapeType, fileMins, fileMaxs );
324 if ( shapetype == SHPT_NULL )
326 shapetype = fileShapeType;
330 prjfilename = (
char *) malloc( filenamelen + 5 );
334 plabort(
"Could not allocate memory for generating map projection filename" );
337 strncpy( prjfilename, name, filenamelen );
338 prjfilename[ filenamelen ] =
'\0';
339 strcat( prjfilename,
".prj" );
341 if ( prjfile && prjfile->
file )
343 fread( prjtype, 1, 6, prjfile->
file );
344 if ( strcmp( prjtype,
"PROJCS" ) == 0 )
362 if ( ( !plotentries && ( entrynumber == nentries ) ) || ( plotentries && ( entryindex == nplotentries ) ) )
366 if ( partnumber == 0 )
369 object = SHPReadObject( in, plotentries[entryindex] );
371 object = SHPReadObject( in, entrynumber );
375 if (
object == NULL )
384 if ( object->nParts == 0 )
385 nVertices =
object->nVertices;
386 else if ( partnumber == ( object->nParts - 1 ) )
387 nVertices =
object->nVertices -
object->panPartStart[partnumber];
389 nVertices =
object->panPartStart[partnumber + 1] -
object->panPartStart[partnumber];
394 if ( object->nParts > 0 )
396 bufxraw =
object->padfX +
object->panPartStart[partnumber];
397 bufyraw =
object->padfY +
object->panPartStart[partnumber];
401 bufxraw =
object->padfX;
402 bufyraw =
object->padfY;
406 minsectlon =
object->dfXMin;
407 maxsectlon =
object->dfXMax;
408 minsectlat =
object->dfYMin;
409 maxsectlat =
object->dfYMax;
415 PLINT nExtraPositiveRedraws = 0;
416 double unrebasedFirstValue = bufxraw[0];
442 unrebasedFirstValue = bufxraw[0];
443 rebaselon( &bufxraw[0], ( minx + maxx ) / 2.0 );
444 rebaseAmount = bufxraw[0] - unrebasedFirstValue;
445 minsectlon += rebaseAmount;
446 maxsectlon += rebaseAmount;
447 for ( i = 1; i < nVertices; i++ )
451 bufxraw[i] += rebaseAmount;
454 difference = bufxraw[i] - bufxraw[i - 1];
455 if ( difference < -180.0 )
458 maxsectlon =
MAX( maxsectlon, bufxraw[i] );
460 else if ( difference > 180.0 )
463 minsectlon =
MIN( minsectlon, bufxraw[i] );
468 if ( ( maxsectlat > miny ) && ( minsectlat < maxy )
469 && ( maxsectlon > minx ) && ( minsectlon < maxx ) )
471 drawmapdata( mapform, shapetype, nVertices, bufxraw, bufyraw, dx, dy, just, text );
474 while ( minsectlon + 360.0 < maxx )
476 for ( i = 0; i < nVertices; ++i )
478 drawmapdata( mapform, shapetype, nVertices, bufxraw, bufyraw, dx, dy, just, text );
480 ++nExtraPositiveRedraws;
482 if ( maxsectlon - 360.0 > minx )
484 for ( i = 0; i < nVertices; ++i )
485 bufxraw[i] -= nExtraPositiveRedraws * 360.0;
486 while ( maxsectlon - 360.0 > minx )
488 for ( i = 0; i < nVertices; ++i )
490 drawmapdata( mapform, shapetype, nVertices, bufxraw, bufyraw, dx, dy, just, text );
497 drawmapdata( mapform, shapetype, nVertices, bufxraw, bufyraw, dx, dy, just, text );
504 if ( partnumber == object->nParts - 1 || object->nParts == 0 )
509 SHPDestroyObject(
object );
521 #endif //HAVE_SHAPELIB 569 drawmap( mapform, name, 0.0, 0.0, SHPT_NULL, 0.0, NULL, minx, maxx,
570 miny, maxy, NULL, 0 );
572 plwarn(
"plmap is a no-op because shapelib is not available." );
599 drawmap( mapform, name, 0.0, 0.0, SHPT_ARC, 0.0,
"", minx, maxx,
600 miny, maxy, plotentries, nplotentries );
602 plwarn(
"plmapline is a no-op because shapelib is not available." );
622 drawmap( mapform, name, 1.0, 0.0, SHPT_POINT, 0.5,
string, minx, maxx,
623 miny, maxy, plotentries, nplotentries );
625 plwarn(
"plmapstring is a no-op because shapelib is not available." );
645 drawmap( mapform, name, dx, dy, SHPT_POINT, just, text, minx, maxx,
646 miny, maxy, &plotentry, 1 );
648 plwarn(
"plmaptex is a no-op because shapelib is not available." );
666 drawmap( mapform, name, 0.0, 0.0, SHPT_POLYGON, 0.0, NULL, minx, maxx,
667 miny, maxy, plotentries, nplotentries );
669 plwarn(
"plmapfill is a no-op because shapelib is not available." );
712 PLFLT yy, xx, temp, x[2], y[2], dx, dy;
714 if ( minlong > maxlong )
720 if ( minlat > maxlat )
726 dx = ( maxlong - minlong ) /
NSEG;
727 dy = ( maxlat - minlat ) /
NSEG;
731 for ( yy = dlat * ceil( minlat / dlat ); yy <= maxlat; yy += dlat )
733 if ( mapform == NULL )
739 for ( xx = minlong; xx < maxlong; xx += dx )
744 ( *mapform )( 2, x, y );
752 for ( xx = dlong * ceil( minlong / dlong ); xx <= maxlong; xx += dlong )
754 if ( mapform == NULL )
760 for ( yy = minlat; yy < maxlat; yy += dy )
765 ( *mapform )( 2, x, y );
796 if ( strstr( message,
"Unable to open" ) == NULL )
797 fprintf( stderr,
"%s\n", message );
805 char *fs = NULL, *dn = NULL;
809 SASetupDefaultHooks( &sHooks );
810 sHooks.Error = CustomErrors;
816 #define SHPOpenLL( a, b, c ) SHPOpen( a, b ) 817 #endif //HAVE_SAHOOKS 825 if ( ( file = SHPOpenLL( fs,
"rb", &sHooks ) ) != NULL )
831 #if defined ( PLPLOT_LIB_ENV ) 836 if ( ( file = SHPOpenLL( fs,
"rb", &sHooks ) ) != NULL )
840 #endif // PLPLOT_LIB_ENV 844 if ( ( file = SHPOpenLL( fn,
"rb", &sHooks ) ) != NULL )
846 pldebug(
"OpenShapeFile",
"Found file %s in current directory.\n", fn );
853 #if defined ( PLPLOT_HOME_ENV ) 858 if ( ( file = SHPOpenLL( fs,
"rb", &sHooks ) ) != NULL )
862 #endif // PLPLOT_HOME_ENV/lib 866 #if defined ( DATA_DIR ) 869 if ( ( file = SHPOpenLL( fs,
"rb", &sHooks ) ) != NULL )
878 if ( ( file = SHPOpenLL( fs,
"rb", &sHooks ) ) != NULL )
883 pldebug(
"OpenShapeFile",
"File %s not found.\n", fn );
888 pldebug(
"OpenShapeFile",
"SHPOpen successfully opened two files with basename %s\n", fs );
892 #endif //ifdef HAVE_SHAPELIB
void plGetName(PLCHAR_VECTOR dir, PLCHAR_VECTOR subdir, PLCHAR_VECTOR filename, char **filespec)
void mapform(PLINT n, PLFLT *x, PLFLT *y)
void plmapline(PLMAPFORM_callback mapform, PLCHAR_VECTOR name, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy, PLINT_VECTOR plotentries, PLINT nplotentries)
const char * PLCHAR_VECTOR
void plmeridians(PLMAPFORM_callback mapform, PLFLT dlong, PLFLT dlat, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat)
void plmaptex(PLMAPFORM_callback mapform, PLCHAR_VECTOR name, PLFLT dx, PLFLT dy, PLFLT just, PLCHAR_VECTOR text, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy, PLINT plotentry)
void plabort(PLCHAR_VECTOR errormsg)
const PLINT * PLINT_VECTOR
void plmapfill(PLMAPFORM_callback mapform, PLCHAR_VECTOR name, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy, PLINT_VECTOR plotentries, PLINT nplotentries)
void(* PLMAPFORM_callback)(PLINT n, PLFLT_NC_VECTOR x, PLFLT_NC_VECTOR y)
int pdf_close(PDFstrm *pdfs)
void plwarn(PLCHAR_VECTOR errormsg)
void plmap(PLMAPFORM_callback mapform, PLCHAR_VECTOR name, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy)
void plmapstring(PLMAPFORM_callback mapform, PLCHAR_VECTOR name, PLCHAR_VECTOR string, PLFLT minx, PLFLT maxx, PLFLT miny, PLFLT maxy, PLINT_VECTOR plotentries, PLINT nplotentries)
PDFstrm * plLibOpenPdfstrm(PLCHAR_VECTOR fn)