Package chunmap.example.grid

Source Code of chunmap.example.grid.ImageCutTest

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.example.grid;

import java.io.IOException;

import chunmap.data.provider.LayerFactory;
import chunmap.raster.grid.GridLayer;
import chunmap.raster.grid.operate.ImageCut;
import chunmap.util.CMAssert;
import chunmap.view.Map;
import chunmap.view.View;
import chunmap.view.ViewPort;
import chunmap.view.layer.VectorLayer;
import chunmap.view.render.GeneralSymbol;
import chunmap.view.render.Painter;
import chunmap.view.render.Style2D;
import chunmap.view.render.Symbol;

/**
* cut map to tileLayer
*
* @author chunquedong
*
*/
public class ImageCutTest {

  private Map map;
  private static int buffer = 3;// 为了消除图片之间的缝隙,读取时和GridDataFactory.buffer保持一致。

  /**
   * @param args
   */
  public static void main(String[] args) {
    ImageCutTest test = new ImageCutTest();
    // test.cut();
    test.autoCut();
  }

  public void cut() {
    init(100, 80);

    String path = "D:\\Temp\\chunmapData";
    try {
      ImageCut imageCut = new ImageCut(map, path);
      imageCut.cut(2, "hello");

    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public GridLayer autoCut() {
    init(500, 400);

    String path = "D:\\Temp\\chunmapData";
    try {
      ImageCut imageCut = new ImageCut(map, path);
      return imageCut.autoCut(3, 3);

    } catch (IOException e) {
      e.printStackTrace();
    }

    throw new CMAssert.AssertionEexception("error on cut to tile");
  }

  private void init(int width, int height) {
    View view = new ViewPort(width, height,buffer);
    Painter painter = new Painter(width + buffer, height + buffer);

    map = new Map(view, painter);

    // Load data
    String path1=
        "D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\region.shp";
    String path2=
        "D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\city1.shp";
    String path3=
        "D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\river.shp";

    VectorLayer layer = (VectorLayerLayerFactory.openShapeFile(path1);
    layer.setDefaultStyle(new Symbol[]{new GeneralSymbol()});
    VectorLayer layer2 = (VectorLayer) LayerFactory.openShapeFile(path2);
    layer2.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style2())});
    VectorLayer layer3 = (VectorLayer) LayerFactory.openShapeFile(path3);
    layer3.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style1())});

    map.getLayerCollection().add(layer);
    map.getLayerCollection().add(layer2);
    map.getLayerCollection().add(layer3);

  }
}
TOP

Related Classes of chunmap.example.grid.ImageCutTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.