use of org.pentaho.gis.shapefiles.ShapePolygon in project pentaho-kettle by pentaho.
the class ShapeFileReader method processRow.
public synchronized boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleStepException {
meta = (ShapeFileReaderMeta) smi;
data = (ShapeFileReaderData) sdi;
boolean retval = true;
if (data.shapeNr >= data.shapeFile.getNrShapes()) {
setOutputDone();
return false;
}
if (first) {
first = false;
data.outputRowMeta = new RowMeta();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
}
// building new row
Object[] outputRow = RowDataUtil.allocateRowData(data.outputRowMeta.size());
int outputIndex;
// getting shape # data.shapeNr from shapefile
// Get the shape from the shapefile
//
ShapeInterface si = data.shapeFile.getShape(data.shapeNr);
switch(si.getType()) {
case Shape.SHAPE_TYPE_POLYLINE_M:
{
// PolyLimeM";
ShapePolyLineM eplm = (ShapePolyLineM) si;
int partnr = 0;
for (int j = 0; j < eplm.nrpoints; j++) {
// PolyLimeM, point #"+j;
for (int k = 0; k < eplm.nrparts; k++) {
if (j == eplm.part_starts[k])
partnr++;
}
outputIndex = 0;
// adding the basics";
// Add the basics...
// The filename...
outputRow[outputIndex++] = meta.getShapeFilename();
// The file type
outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
// The shape nr
outputRow[outputIndex++] = new Long(data.shapeNr + 1);
// The part nr
outputRow[outputIndex++] = new Long(partnr);
// The nr of parts
outputRow[outputIndex++] = new Long(eplm.nrparts);
// The point nr
outputRow[outputIndex++] = new Long(j + 1);
// The nr of points
outputRow[outputIndex++] = new Long(eplm.nrpoints);
// The X coordinate
outputRow[outputIndex++] = new Double(eplm.point[j].x);
// The Y coordinate
outputRow[outputIndex++] = new Double(eplm.point[j].y);
// The measure
outputRow[outputIndex++] = new Double(eplm.measures[j]);
// The Values in the DBF file...
// PolyLimeM, point #"+j+", add dbf data";
Object[] dbfData = si.getDbfData();
RowMetaInterface dbfMeta = si.getDbfMeta();
for (int d = 0; d < dbfMeta.size(); d++) {
outputRow[outputIndex++] = dbfData[d];
}
linesInput++;
// Put it out to the rest of the world...
putRow(data.outputRowMeta, outputRow);
}
}
break;
case Shape.SHAPE_TYPE_POLYGON:
{
// ShapePolygon";
ShapePolygon epl = (ShapePolygon) si;
int partnr = 0;
for (int j = 0; j < epl.nrpoints; j++) {
// PolyLime, point #"+j;
for (int k = 0; k < epl.nrparts; k++) {
if (j == epl.part_starts[k])
partnr++;
}
outputIndex = 0;
// adding the basics";
// Add the basics...
// The filename...
outputRow[outputIndex++] = meta.getShapeFilename();
// The file type
outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
// The shape nr
outputRow[outputIndex++] = new Long(data.shapeNr + 1);
// The part nr
outputRow[outputIndex++] = new Long(partnr);
// The nr of parts
outputRow[outputIndex++] = new Long(epl.nrparts);
// The point nr
outputRow[outputIndex++] = new Long(j + 1);
// The nr of points
outputRow[outputIndex++] = new Long(epl.nrpoints);
// The X coordinate
outputRow[outputIndex++] = new Double(epl.point[j].x);
// The Y coordinate
outputRow[outputIndex++] = new Double(epl.point[j].y);
// The measure
outputRow[outputIndex++] = new Double(0.0);
// The Values in the DBF file...
// PolyLime, point #"+j+", add dbf data";
//
Object[] dbfData = si.getDbfData();
RowMetaInterface dbfMeta = si.getDbfMeta();
for (int d = 0; d < dbfMeta.size(); d++) {
outputRow[outputIndex++] = dbfData[d];
}
linesInput++;
// Put it out to the rest of the world...
putRow(data.outputRowMeta, outputRow);
}
}
break;
case Shape.SHAPE_TYPE_POLYLINE:
{
// PolyLime";
ShapePolyLine epl = (ShapePolyLine) si;
int partnr = 0;
for (int j = 0; j < epl.nrpoints; j++) {
// PolyLime, point #"+j;
for (int k = 0; k < epl.nrparts; k++) {
if (j == epl.part_starts[k])
partnr++;
}
outputIndex = 0;
// adding the basics";
// Add the basics...
// The filename...
outputRow[outputIndex++] = meta.getShapeFilename();
// The file type
outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
// The shape nr
outputRow[outputIndex++] = new Long(data.shapeNr + 1);
// The part nr
outputRow[outputIndex++] = new Long(partnr);
// The nr of parts
outputRow[outputIndex++] = new Long(epl.nrparts);
// The point nr
outputRow[outputIndex++] = new Long(j + 1);
// The nr of points
outputRow[outputIndex++] = new Long(epl.nrpoints);
// The X coordinate
outputRow[outputIndex++] = new Double(epl.point[j].x);
// The Y coordinate
outputRow[outputIndex++] = new Double(epl.point[j].y);
// The measure
outputRow[outputIndex++] = new Double(0.0);
// The Values in the DBF file...
// PolyLime, point #"+j+", add dbf data";
//
Object[] dbfData = si.getDbfData();
RowMetaInterface dbfMeta = si.getDbfMeta();
for (int d = 0; d < dbfMeta.size(); d++) {
outputRow[outputIndex++] = dbfData[d];
}
linesInput++;
// Put it out to the rest of the world...
putRow(data.outputRowMeta, outputRow);
}
}
break;
case Shape.SHAPE_TYPE_POINT:
{
// Point";
ShapePoint ep = (ShapePoint) si;
// Add the basics...
outputIndex = 0;
// The filename...
outputRow[outputIndex++] = meta.getShapeFilename();
// The file type
outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
// The shape nr
outputRow[outputIndex++] = new Long(data.shapeNr);
// The part nr
outputRow[outputIndex++] = new Long(0L);
// The nr of parts
outputRow[outputIndex++] = new Long(0L);
// The point nr
outputRow[outputIndex++] = new Long(0L);
// The nr of points
outputRow[outputIndex++] = new Long(0L);
// The X coordinate
outputRow[outputIndex++] = new Double(ep.x);
// The Y coordinate
outputRow[outputIndex++] = new Double(ep.y);
// The measure
outputRow[outputIndex++] = new Double(0.0);
// The Values in the DBF file...
// PolyLimeM, point #"+data.shapeNr+", add dbf data";
//
Object[] dbfData = si.getDbfData();
RowMetaInterface dbfMeta = si.getDbfMeta();
for (int d = 0; d < dbfMeta.size(); d++) {
outputRow[outputIndex++] = dbfData[d];
}
linesInput++;
// Put it out to the rest of the world...
putRow(data.outputRowMeta, outputRow);
}
break;
default:
System.out.println("Unable to parse shape type [" + Shape.getEsriTypeDesc(si.getType()) + "] : not yet implemented.");
throw new KettleStepException("Unable to parse shape type [" + Shape.getEsriTypeDesc(si.getType()) + "] : not yet implemented.");
}
// Next shape please!
data.shapeNr++;
if ((linesInput % Const.ROWS_UPDATE) == 0)
logBasic("linenr " + linesInput);
return retval;
}
Aggregations