如何用Java写出泰森多边形算法代码???我找了好多资源表示无解呀?

如题所述

package com.wangyin.seapay.loginkgo;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.process.Process;
import org.geotools.process.ProcessException;
import org.geotools.process.ProcessFactory;
import org.geotools.process.spatialstatistics.core.Params;
import org.geotools.process.spatialstatistics.enumeration.ThiessenAttributeMode;
import org.geotools.process.spatialstatistics.operations.ThiessenPolygonOperation;
import org.geotools.text.Text;
import org.geotools.util.NullProgressListener;
import org.geotools.util.logging.Logging;
import org.opengis.util.ProgressListener;

import com.vividsolutions.jts.geom.Geometry;

/**
 * Created by hanxiaofei on 2018/4/11.
 */
public class ThiessenPolygonProcess extends AbstractStatisticsProcess {
    protected static final Logger LOGGER = Logging.getLogger(ThiessenPolygonProcess.class);

    private boolean started = false;

    public ThiessenPolygonProcess(ProcessFactory factory) {
        super(factory);
    }

    public ProcessFactory getFactory() {
        return factory;
    }

    public static SimpleFeatureCollection process(SimpleFeatureCollection inputFeatures,
                                                  ThiessenAttributeMode attributes, Geometry clipArea, ProgressListener monitor) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ThiessenPolygonProcessFactory.inputFeatures.key, inputFeatures);
        map.put(ThiessenPolygonProcessFactory.attributes.key, attributes);
        map.put(ThiessenPolygonProcessFactory.clipArea.key, clipArea);

        Process process = new ThiessenPolygonProcess(null);
        Map<String, Object> resultMap;
        try {
            resultMap = process.execute(map, monitor);
            return (SimpleFeatureCollection) resultMap
                    .get(ThiessenPolygonProcessFactory.RESULT.key);
        } catch (ProcessException e) {
            LOGGER.log(Level.FINER, e.getMessage(), e);
        }

        return null;
    }

    @Override
    public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor)
            throws ProcessException {
        if (started)
            throw new IllegalStateException("Process can only be run once");
        started = true;

        if (monitor == null)
            monitor = new NullProgressListener();
        try {
            monitor.started();
            monitor.setTask(Text.text("Grabbing arguments"));
            monitor.progress(10.0f);

            SimpleFeatureCollection inputFeatures = (SimpleFeatureCollection) Params.getValue(
                    input, ThiessenPolygonProcessFactory.inputFeatures, null);
            if (inputFeatures == null) {
                throw new NullPointerException("inputFeatures parameter required");
            }

            ThiessenAttributeMode attributes = (ThiessenAttributeMode) Params.getValue(input,
                    ThiessenPolygonProcessFactory.attributes,
                    ThiessenPolygonProcessFactory.attributes.sample);

            Geometry clipArea = (Geometry) Params.getValue(input,
                    ThiessenPolygonProcessFactory.clipArea, null);

            monitor.setTask(Text.text("Processing ..."));
            monitor.progress(25.0f);

            if (monitor.isCanceled()) {
                return null; // user has canceled this operation
            }

            // start process
            ThiessenPolygonOperation operation = new ThiessenPolygonOperation();
            operation.setAttributeMode(attributes);
            if (clipArea != null) {
                operation.setClipArea(clipArea);
            }
            SimpleFeatureCollection resultFc = operation.execute(inputFeatures);
            // end process

            monitor.setTask(Text.text("Encoding result"));
            monitor.progress(90.0f);

            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put(ThiessenPolygonProcessFactory.RESULT.key, resultFc);
            monitor.complete(); // same as 100.0f

            return resultMap;
        } catch (Exception eek) {
            monitor.exceptionOccurred(eek);
            return null;
        } finally {
            monitor.dispose();
        }
    }

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-03-23
你好,在ArcGIS中生成泰森多边形比较简单。首先你得有一个点图层,例如城市点。其次你的点图层文件中得有字段,比如城市人口。最后实现:【ArcToolbox】窗口——【分析工具】——【邻域分析】——双击【创建泰森多边形】,打开【创建泰森多边形】对话框,里面的参数设置都很简单,一看就懂。最后输出的图形就是泰森多边形。本回答被网友采纳
第2个回答  2018-04-11
首先要找到它的所有邻区,知道邻区就好算了啊。
第3个回答  2016-03-22
基于数学。。对函数算法要求比较高。。
第4个回答  2016-03-22
有解,只是麻烦。都是线性函数的问题
相似回答