📄 shputils.c
字号:
/****************************************************************************** * $Id: shputils.c,v 1.4 1999/11/05 14:12:05 warmerda Exp $ * * Project: Shapelib * Purpose: * Altered "shpdump" and "dbfdump" to allow two files to be appended. * Other Functions: * Selecting from the DBF before the write occurs. * Change the UNITS between Feet and Meters and Shift X,Y. * Clip and Erase boundary. * * Bill Miller NC-DOT -- Feb. 1997 -- bmiller@doh.dot.state.nc.us * There was not a lot of time to debug hidden problems; * And the code is not very well organized or documented. * The clip/erase function was not well tested. * * PURPOSE: I needed a program to Append, Select, Change Unit, and * Clip boundaries. The program only passes thru the * data once. * * Author: Bill Miller (bmiller@doh.dot.state.nc.us) * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * This software is available under the following "MIT Style" license, * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This * option is discussed in more detail in shapelib.html. * * -- * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: shputils.c,v $ * Revision 1.4 1999/11/05 14:12:05 warmerda * updated license terms * * Revision 1.3 1998/12/03 15:47:39 warmerda * Did a bunch of rewriting to make it work with the V1.2 API. * * Revision 1.2 1998/06/18 01:19:49 warmerda * Made C++ compilable. * * Revision 1.1 1997/05/27 20:40:27 warmerda * Initial revision */static char rcsid[] = "$Id: shputils.c,v 1.4 1999/11/05 14:12:05 warmerda Exp $";#include "shapefil.h"#include "string.h"#ifndef FALSE# define FALSE 0# define TRUE 1#endifchar infile[80], outfile[80], temp[400];/* Variables for shape files */SHPHandle hSHP;SHPHandle hSHPappend;int nShapeType, nEntities, iPart;int nShapeTypeAppend, nEntitiesAppend;SHPObject *psCShape;double adfBoundsMin[4], adfBoundsMax[4];/* Variables for DBF files */DBFHandle hDBF;DBFHandle hDBFappend; DBFFieldType iType;DBFFieldType jType; char iszTitle[12];char jszTitle[12];int *pt;char iszFormat[32], iszField[1024];char jszFormat[32], jszField[1024];int i, ti, iWidth, iDecimals, iRecord;int j, tj, jWidth, jDecimals, jRecord;int found, newdbf;void openfiles(void);void setext(char *pt, char *ext);int strncasecmp2(char *s1, char *s2, int n);void mergefields(void);void findselect(void);void showitems(void);int selectrec();int check_theme_bnd();int clip();void error();/* -------------------------------------------------------------------- *//* Variables for the SELECT function *//* -------------------------------------------------------------------- */ char selectitem[40], *cpt; int selectvalues[150]; int iselect = FALSE, iselectitem = -1, selcount=0; int iunselect = FALSE;/* -------------------------------------------------------------------- *//* Variables for the CLIP and ERASE functions *//* -------------------------------------------------------------------- */ double cxmin, cymin, cxmax, cymax; int iclip = FALSE, ierase = FALSE; int itouch = FALSE, iinside = FALSE, icut = FALSE; int ibound = FALSE, ipoly = FALSE; char clipfile[80];/* -------------------------------------------------------------------- *//* Variables for the UNIT function *//* -------------------------------------------------------------------- */ double factor = 1; /* NO FACTOR */ int iunit = FALSE; /* -------------------------------------------------------------------- *//* Variables for the SHIFT function *//* -------------------------------------------------------------------- */ double xshift = 0, yshift = 0; /* NO SHIFT */ int main( int argc, char ** argv ){/* -------------------------------------------------------------------- *//* Check command line usage. *//* -------------------------------------------------------------------- */ if( argc < 2 ) error(); strcpy(infile, argv[1]); if (argc == 2 ) { setext(infile, "shp"); printf("DESCRIBE: %s\n",infile); strcpy(outfile,""); } else { strcpy(outfile,argv[2]); }/* -------------------------------------------------------------------- *//* Look for other functions on the command line. (SELECT, UNIT) *//* -------------------------------------------------------------------- */ for (i = 3; i < argc; i++) { if ((strncasecmp2(argv[i], "SEL",3) == 0) || (strncasecmp2(argv[i], "UNSEL",5) == 0)) { if (strncasecmp2(argv[i], "UNSEL",5) == 0) iunselect=TRUE; i++; if (i >= argc) error(); strcpy(selectitem,argv[i]); i++; if (i >= argc) error(); selcount=0; strcpy(temp,argv[i]); cpt=temp; tj = atoi(cpt); ti = 0; while (tj>0) { selectvalues[selcount] = tj; while( *cpt >= '0' && *cpt <= '9') cpt++; while( *cpt > '\0' && (*cpt < '0' || *cpt > '9') ) cpt++; tj=atoi(cpt); selcount++; } iselect=TRUE; } else if ((strncasecmp2(argv[i], "CLIP",4) == 0) || (strncasecmp2(argv[i], "ERASE",5) == 0)) { if (strncasecmp2(argv[i], "ERASE",5) == 0) ierase=TRUE; i++; if (i >= argc) error(); strcpy(clipfile,argv[i]); sscanf(argv[i],"%lf",&cxmin); i++; if (i >= argc) error(); if (strncasecmp2(argv[i], "BOUND",5) == 0) { setext(clipfile, "shp"); hSHP = SHPOpen( clipfile, "rb" ); if( hSHP == NULL ) { printf( "ERROR: Unable to open the clip shape file:%s\n", clipfile ); exit( 1 ); } SHPGetInfo( hSHPappend, NULL, NULL, adfBoundsMin, adfBoundsMax ); cxmin = adfBoundsMin[0]; cymin = adfBoundsMin[1]; cxmax = adfBoundsMax[0]; cymax = adfBoundsMax[1]; printf("Theme Clip Boundary: (%lf,%lf) - (%lf,%lf)\n", cxmin, cymin, cxmax, cymax); ibound=TRUE; } else if (strncasecmp2(argv[i], "POLY",4) == 0) { ipoly=TRUE; } else { /*** xmin,ymin,xmax,ymax ***/ sscanf(argv[i],"%lf",&cymin); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&cxmax); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&cymax); printf("Clip Box: (%lf,%lf) - (%lf,%lf)\n",cxmin, cymin, cxmax, cymax); } i++; if (i >= argc) error(); if (strncasecmp2(argv[i], "CUT",3) == 0) icut=TRUE; else if (strncasecmp2(argv[i], "TOUCH",5) == 0) itouch=TRUE; else if (strncasecmp2(argv[i], "INSIDE",6) == 0) iinside=TRUE; else error(); iclip=TRUE; } else if (strncasecmp2(argv[i], "UNIT",4) == 0) { i++; if (i >= argc) error(); if (strncasecmp2(argv[i], "METER",5) == 0) factor=0.304800609601; else { if (strncasecmp2(argv[i], "FEET",4) == 0) factor=3.280833; else sscanf(argv[i],"%lf",&factor); } if (factor == 0) error(); iunit=TRUE; printf("Output file coordinate values will be factored by %lg\n",factor); } else if (strncasecmp2(argv[i],"SHIFT",5) == 0) { i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&xshift); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&yshift); iunit=TRUE; printf("X Shift: %lg Y Shift: %lg\n",xshift,yshift); } else { printf("ERROR: Unknown function %s\n",argv[i]); error(); } }/* -------------------------------------------------------------------- *//* If there is no data in this file let the user know. *//* -------------------------------------------------------------------- */ openfiles(); /* Open the infile and the outfile for shape and dbf. */ if( DBFGetFieldCount(hDBF) == 0 ) { puts( "There are no fields in this table!" ); exit( 1 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -