org.jgrasstools.gears.io.dbf.DbfTableReader Maven / Gradle / Ivy
/*
* This file is part of JGrasstools (http://www.jgrasstools.org)
* (C) HydroloGIS - www.hydrologis.com
*
* JGrasstools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.jgrasstools.gears.io.dbf;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import oms3.annotations.Author;
import oms3.annotations.Description;
import oms3.annotations.Execute;
import oms3.annotations.In;
import oms3.annotations.Keywords;
import oms3.annotations.Label;
import oms3.annotations.License;
import oms3.annotations.Name;
import oms3.annotations.Out;
import oms3.annotations.Status;
import oms3.annotations.UI;
import org.geotools.data.shapefile.dbf.DbaseFileHeader;
import org.geotools.data.shapefile.dbf.DbaseFileReader;
import org.jgrasstools.gears.libs.modules.JGTConstants;
import org.jgrasstools.gears.libs.modules.JGTModel;
@Description("Utility class for reading dbf tables.")
@Author(name = "Andrea Antonello", contact = "http://www.hydrologis.com")
@Keywords("IO, Shapefile, Feature, Vector, Reading")
@Label(JGTConstants.HASHMAP_READER)
@Status(Status.DRAFT)
@Name("dbfreader")
@License("General Public License Version 3 (GPLv3)")
public class DbfTableReader extends JGTModel {
@Description("The dbf file.")
@UI(JGTConstants.FILEIN_UI_HINT)
@In
public String file = null;
@Description("The read dbf table.")
@Out
public HashMap> outTabledata = null;
@Execute
public void readTable() throws IOException {
if (!concatOr(outTabledata == null, doReset)) {
return;
}
FileInputStream fis = null;
DbaseFileReader dbfReader = null;
try {
fis = new FileInputStream(file);
dbfReader = new DbaseFileReader(fis.getChannel(), false, Charset.defaultCharset());
final DbaseFileHeader header = dbfReader.getHeader();
int numFields = header.getNumFields();
outTabledata = new HashMap>();
for( int i = 0; i < numFields; i++ ) {
String fieldName = header.getFieldName(i);
outTabledata.put(fieldName, new ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy