Skip to content
shputils.c 40.3 KiB
Newer Older
    puts( "Ex: shputils in.shp out.shp   SELECT countycode 3,5,9,13,17,27");
    puts( "    shputils in.shp out.shp   CLIP   10 10 90 90 Touch   FACTOR Meter Feet");
    puts( "    shputils in.shp out.shp   FACTOR Meter 3.0");
    puts( "    shputils in.shp out.shp   CLIP   clip.shp Boundary Touch   SHIFT 40 40");
    puts( "    shputils in.shp out.shp   SELECT co 112   CLIP clip.shp Boundary Touch\n");
    puts( "USAGE: shputils  <DescribeShape>   {ALL}");
    puts( "USAGE: shputils  <InputShape>  <OutShape|AppendShape>" );
    puts( "   { <FACTOR>       <FEET|MILES|METERS|KM> <FEET|MILES|METERS|KM|factor> }" );
    puts( "   { <SHIFT>        <xshift> <yshift> }" );
    puts( "   { <SELECT|UNSEL> <Item> <valuelist> }" );
    puts( "   { <CLIP|ERASE>   <xmin> <ymin> <xmax> <ymax> <TOUCH|INSIDE|CUT> }" );
    puts( "   { <CLIP|ERASE>   <theme>      <BOUNDARY>     <TOUCH|INSIDE|CUT> }" );
    puts( "     Note: CUT is not complete and does not create intersections.");
    puts( "           For more information read programmer comment.");
	
    /****   Clip functions for Polygon and Cut is not supported
            There are several web pages that describe methods of doing this function.
            It seem easy to impliment until you start writting code.  I don't have the
            time to add these functions but a did leave a simple cut routine in the 
            program that can be called by using CUT instead of TOUCH in the 
            CLIP or ERASE functions.  It does not add the intersection of the line and
            the clip box, so polygons could look incomplete and lines will come up short.
	
            Information about clipping lines with a box:
            http://www.csclub.uwaterloo.ca/u/mpslager/articles/sutherland/wr.html
            Information about finding the intersection of two lines:
            http://www.whisqu.se/per/docs/math28.htm
	   
            THE CODE LOOKS LIKE THIS:
            ********************************************************	  
            void Intersect_Lines(float x0,float y0,float x1,float y1,
            float x2,float y2,float x3,float y3,
            float *xi,float *yi)
            {
//  this function computes the intersection of the sent lines
//  and returns the intersection point, note that the function assumes
//  the lines intersect. the function can handle vertical as well
//  as horizontal lines. note the function isn't very clever, it simply
//  applies the math, but we don't need speed since this is a
//  pre-processing step
//  The Intersect_lines program came from (http://www.whisqu.se/per/docs/math28.htm)

float a1,b1,c1, // constants of linear equations 
a2,b2,c2,
det_inv,  // the inverse of the determinant of the coefficientmatrix
m1,m2;    // the slopes of each line
      
// compute slopes, note the cludge for infinity, however, this will
// be close enough
if ((x1-x0)!=0)
m1 = (y1-y0)/(x1-x0);
else
m1 = (float)1e+10;  // close enough to infinity
   
   
if ((x3-x2)!=0) 
m2 = (y3-y2)/(x3-x2);
else
m2 = (float)1e+10;  // close enough to infinity
   
// compute constants
a1 = m1;
a2 = m2;
b1 = -1;
b2 = -1;
c1 = (y0-m1*x0);
c2 = (y2-m2*x2);
// compute the inverse of the determinate
det_inv = 1/(a1*b2 - a2*b1);
// use Kramers rule to compute xi and yi
*xi=((b1*c2 - b2*c1)*det_inv);
*yi=((a2*c1 - a1*c2)*det_inv);
} // end Intersect_Lines
    **********************************************************/

    exit( 1 );
}