1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| private void readPolyline(boolean filled) throws IOException
{
// skip bounding box.
double xMin = readDouble();
double yMin = readDouble();
double xMax = readDouble();
double yMax = readDouble();
double x, y;
// Read number of parts in the current shape.
int nParts = readInt();
// Read total number of points in the current shape.
int nPoints = readInt();
// Read start index for each part
int parts[] = new int[nParts];
for(int i = 0; i < nParts; i++)
{
parts[i] = readInt();
}
// Compute the corresponding number of points for each part
int nums[] = new int[nParts];
for(int i = 0; i < nParts; i++)
{
if(i != nParts - 1)
{
nums[i] = parts[i + 1] - parts[i];
}
else
{
nums[i] = nPoints - parts[i];
}
}
// Array for points to read
double xi[] = null;
double yi[] = null;
int currentPart = 0;
int p = 0;
// Color col = new Color((float)Math.random(), (float)Math.random(), (float)Math.random());
// Read until the total number of points has been read.
for(int i = 0; i < nPoints; )
{
// Starting points of a part
if(i == parts[currentPart])
{
// Number of points for that part
int np = nums[currentPart];
if(np <= 0)
{
continue;
}
// Read all points
xi = new double[np];
yi = new double[np];
for(int j = 0; j < np; j++)
{
x = readDouble();
y = readDouble();
if(j == 0)
{
xMin = x;
yMin = y;
xMax = x;
yMax = y;
}
else
{
xMin = Math.min(x, xMin);
yMin = Math.min(y, yMin);
xMax = Math.max(x, xMax);
yMax = Math.max(y, yMax);
}
if(_projection != null)
{
if((x > 180) || (x < -180))
{
xi[j] = x;
yi[j] = y;
}
else
{
_projection.project(xToRadians(x), yToRadians(y), _projected);
xi[j] = _projected.x;
yi[j] = _projected.y;
}
}
else
{
xi[j] = x;
yi[j] = y;
}
i++; // increment the number of points we've read
}
// Create Polyline or Polylgon
if(filled)
{
GISPolyline poly = new GISPolyline.Double(xi, yi, LxGisPolyline.FILLED_POLY);
_data.addObject(poly, _currentLayerIndex, 0);
// poly.setStatus(col);
poly.setID(new Integer(_currentShape));
_shapes.addElement(poly);
if(_isLabellized)
{
poly.setType(GISPolyline.HIDDEN_POLY);
}
}
else
{
GISPolyline poly = new GISPolyline.Double(xi, yi, GISPolyline.OPENED_POLY);
_data.addObject(poly, _currentLayerIndex, 0);
_shapes.addElement(poly);
poly.setID(new Integer(_currentShape));
if(_isLabellized)
{
poly.setType(GISPolyline.HIDDEN_POLY);
}
}
// Next part
currentPart++;
}
}
} |
Partager