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

本文介绍了一个Java实现泰森多边形算法的示例,通过`ThiessenPolygonProcess`类展示了如何处理输入特征、设置属性模式和裁剪区域,最终执行泰森多边形操作。
摘要由CSDN通过智能技术生成

展开全部

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 map = new HashMap();

map.put(ThiessenPolygonProcessFactory.inputFeatures.key, inputFeatures);

map.put(ThiessenPolygonProcessFactory.attributes.key, attributes);

map.put(ThiessenPolygonProcessFactory.clipArea.key, clipArea);

Process process = new ThiessenPolygonProcess(null);

Map 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;

}

@62616964757a686964616fe58685e5aeb931333365646262Override

public Map execute(Map 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 resultMap = new HashMap();

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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值