view gnv-artifacts/src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java @ 1115:f953c9a559d8

Added license file and license headers. gnv-artifacts/trunk@1260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:46:55 +0000
parents 22c18083225e
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.exports;

import com.vividsolutions.jts.geom.Point;

import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;

import de.intevation.gnv.geobackend.base.Result;

import de.intevation.gnv.state.exception.StateException;

import org.apache.log4j.Logger;

/**
 * This class is a specialization of <code>DefaultDataCollector</code>. The
 * difference between these classes is, that this class extracts points served
 * by a wkt string.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ShapeDataCollector
extends DefaultDataCollector
{
    /**
     * Logger used for logging with log4j.
     */
    private Logger log = Logger.getLogger(ShapeDataCollector.class);

    /**
     * WKTReader to parse points from wkt strings.
     */
    protected WKTReader wktReader = new WKTReader();

    /**
     * Constructor
     *
     * @param names Attributes used to be extracted.
     */
    public ShapeDataCollector(String[] names) {
        super(names);
    }

    /**
     * This method takes point from wkt strings as well and split them into x
     * and y coordinate.
     *
     * @see de.intevation.gnv.exports.Export.DataCollector#getData(Result)
     */
    public String[] getData(Result result)
    throws StateException {

        if (rd == null)
            init(result);

        try {
            String [] entries = new String[names.length+1];
            int j             = 0;
            for (int i = 0; i < names.length; i++) {

                if (names[i].equals("SHAPE")) {
                    Point p  = (Point)wktReader.read(result.getString("SHAPE"));

                    entries[j++] = ""+p.getX();
                    entries[j++] = ""+p.getY();
                }
                else {
                    entries[j++] = result.getString(names[i]);
                }
            }

            return entries;
        }
        catch (ParseException pe) {
            log.error(pe, pe);
            throw new StateException(
                "Error occured while parsing a Point from WKT.");
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org