📄 shputils.c
字号:
{ pt[i]=i; found=1; } } if (found == 0 && jRecord == 0) /* Add missing field to the append table */ { /* The output DBF must be is empty */ pt[i]=tj; tj++; if( !DBFAddField( hDBFappend, iszTitle, iType, iWidth, iDecimals )) { printf( "Warning: DBFAddField(%s, TYPE:%d, WIDTH:%d DEC:%d, ITEM#:%d of %d) failed.\n", iszTitle, iType, iWidth, iDecimals, (i+1), (ti+1) ); pt[i]=-1; } } }}void findselect(){ /* Find the select field name */ iselectitem = -1; for( i = 0; i < ti && iselectitem < 0; i++ ) { iType = DBFGetFieldInfo( hDBF, i, iszTitle, &iWidth, &iDecimals ); if (strncasecmp2(iszTitle, selectitem, 0) == 0) iselectitem = i; } if (iselectitem == -1) { printf("Warning: Item not found for selection (%s)\n",selectitem); iselect = 0; showitems(); printf("Continued... (Selecting entire file)\n"); } /* Extract all of the select values (by field type) */ }void showitems(){ printf("Available Items: "); for( i = 0; i < ti; i++ ) { iType = DBFGetFieldInfo( hDBF, i, iszTitle, &iWidth, &iDecimals ); printf("%s, ",iszTitle); } printf("(total=%d)\n",ti);}int selectrec(){int value, ty; ty = DBFGetFieldInfo( hDBF, iselectitem, NULL, &iWidth, &iDecimals); switch(ty) { case FTString: break; case FTInteger: value = DBFReadIntegerAttribute( hDBF, iRecord, iselectitem ); for (j = 0; j<selcount; j++) { if (selectvalues[j] == value) if (iunselect) return(0); /* Keep this record */ else return(1); /* Skip this record */ } break; case FTDouble: break; } if (iunselect) return(1); /* Skip this record */ else return(0); /* Keep this record */}int check_theme_bnd(){ if ( (adfBoundsMin[0] >= cxmin) && (adfBoundsMax[0] <= cxmax) && (adfBoundsMin[1] >= cymin) && (adfBoundsMax[1] <= cymax) ) { /** Theme is totally inside clip area **/ if (ierase) nEntities=0; /** SKIP THEME **/ else iclip=FALSE; /** WRITE THEME (Clip not needed) **/ } if ( ( (adfBoundsMin[0] < cxmin) && (adfBoundsMax[0] < cxmin) ) || ( (adfBoundsMin[1] < cymin) && (adfBoundsMax[1] < cymin) ) || ( (adfBoundsMin[0] > cxmax) && (adfBoundsMax[0] > cxmax) ) || ( (adfBoundsMin[1] > cymax) && (adfBoundsMax[1] > cymax) ) ) { /** Theme is totally outside clip area **/ if (ierase) iclip=FALSE; /** WRITE THEME (Clip not needed) **/ else nEntities=0; /** SKIP THEME **/ } if (nEntities == 0) puts("WARNING: Theme is outside the clip area."); /** SKIP THEME **/}int clip(){ int outside=FALSE; int j2=0, i2=0; if ( (psCShape->dfXMin >= cxmin) && (psCShape->dfXMax <= cxmax) && (psCShape->dfYMin >= cymin) && (psCShape->dfYMax <= cymax) ) { /** Feature is totally inside clip area **/ if (ierase) return(0); /** SKIP RECORD **/ else return(1); /** WRITE RECORD **/ } if ( ( psCShape->dfXMax < cxmin ) || ( psCShape->dfYMax < cymin ) || ( psCShape->dfXMin > cxmax ) || ( psCShape->dfYMin > cymax ) ) { /** Feature is totally outside clip area **/ if (ierase) return(1); /** WRITE RECORD **/ else return(0); /** SKIP RECORD **/ } if (itouch) { if (ierase) return(0); /** SKIP RECORD **/ else return(1); /** WRITE RECORD **/ } if (iinside) { if (ierase) return(1); /** WRITE RECORD **/ else return(0); /** SKIP RECORD **/ } /*** SECOND check each vertex in the feature ***/ for( j2 = 0; j2 < psCShape->nVertices; j2++ ) { if (psCShape->padfX[j2] < cxmin || psCShape->padfX[j2] > cxmax) { outside=TRUE; } else { if (psCShape->padfY[j2] < cymin || psCShape->padfY[j2] > cymax) outside=TRUE; else outside=FALSE; } if (icut) { if (outside) { } else { if (i2 != j2) { /* write vertex */ psCShape->padfX[i2] = psCShape->padfX[j2]; psCShape->padfY[i2] = psCShape->padfY[j2]; } i2++; } } else if (outside) /* vertex is outside boundary */ { if (iinside) { if (ierase) return(1); /** WRITE RECORD **/ else return(0); /** SKIP RECORD **/ } } else /* vertex is inside boundary */ { if (itouch) { if (ierase) return(0); /** SKIP RECORD **/ else return(1); /** WRITE RECORD **/ } } } if (icut) { j2 = psCShape->nVertices; if (i2 < 2) return(0); /** SKIP RECORD **/ psCShape->nVertices = i2; printf("Vertices:%d OUT:%d Number of Parts:%d\n", j2, psCShape->nVertices, psCShape->nParts ); } if (itouch) { if (ierase) return(1); /** WRITE RECORD **/ else return(0); /** SKIP RECORD **/ } if (iinside) { if (ierase) return(0); /** SKIP RECORD **/ else return(1); /** WRITE RECORD **/ }}/* -------------------------------------------------------------------- *//* Display a usage message. *//* -------------------------------------------------------------------- */void error() { puts( "USAGE: shputils <DescribeShape>"); puts( "USAGE: shputils <InputShape> <AppendShape>" ); puts( " { <SELECT> <Item> <valuelist> }" ); puts( " { <UNSELECT> <Item> <valuelist> }" ); puts( " { <CLIP> <xmin> <ymin> <xmax> <ymax> <TOUCH|INSIDE|CUT> }" ); puts( " { <CLIP> <Theme> <BOUNDARY|POLYGON> <TOUCH|INSIDE|CUT> }" ); puts( " Clip functions for Cut and Polygon are not supported yet..." ); puts( " { <ERASE> <xmin> <ymin> <xmax> <ymax> <TOUCH|INSIDE|CUT> }" ); puts( " { <ERASE> <Theme> <BOUNDARY|POLYGON> <TOUCH|INSIDE|CUT> }" ); puts( " { <UNIT> <FEET|METERS|factor> }" ); puts( " { <SHIFT> <xshift> <yshift> }\n" ); puts( "The program will append to an existing shape file or it will" ); puts( "create a new file if needed." ); puts( "Only the items in the first output file will be preserved." ); puts( "When an item does not match with the append theme then the item"); puts( "might be placed to an existing item at the same position and type." ); puts( " OTHER FUNCTIONS:" ); puts( " - Select a group of shapes from a comma separated selection list."); puts( " - UnSelect a group of shapes from a comma separated selection list."); puts( " - Clip boundary extent or by theme boundary." ); puts( " Touch writes all the shapes that touch the boundary."); puts( " Inside writes all the shapes that are completely within the boundary."); puts( " *(N/A) Cut will cookie-cut shapes that are touching the boundary."); puts( " Boundary clips are only the min and max of a theme boundary." ); puts( " *(N/A) Polygon clips use the polygons within a theme."); puts( " - Erase boundary extent or by theme boundary." ); puts( " Erase is the direct opposite of the Clip function." ); puts( " - Change coordinate value units between meters and feet."); puts( " There is no way to determine the input unit of a shape file."); puts( " Skip this function if the shape file is already in the correct unit."); puts( " Clip and Erase will be done before the unit is changed."); puts( " A shift will be done after the unit is changed."); puts( " - Shift X and Y coordinates.\n" ); puts( "Finally, There can only be one select or unselect in the command line."); puts( " There can only be one clip or erase in the command line."); puts( " There can only be one unit and only one shift in the command line."); puts( "EX: shputils in.shp out.shp CLIP 10 10 90 90 Touch UNIT Feet SHIFT 40 40"); puts( " shputils in.shp out.shp SELECT countycode 3,5,9,13,17,27"); exit( 1 ); }/************************************************************************//* strncasecmp2() *//* *//* Compare two strings up to n characters *//* If n=0 then s1 and s2 must be an exact match *//************************************************************************/int strncasecmp2(char *s1, char *s2, int n){int j,i; if (n<1) n=strlen(s1)+1; for (i=0; i<n; i++) { if (*s1 != *s2) { if (*s1 >= 'a' && *s1 <= 'z') { j=*s1-32; if (j != *s2) return(1); } else { j=*s1+32; if (j != *s2) return(1); } } s1++; s2++; } return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -