반응형
package hello;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.coverage.grid.io.GridFormatFinder;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.filter.text.cql2.CQLException;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.geojson.feature.FeatureJSON;
import org.geotools.referencing.CRS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
import org.opengis.geometry.Envelope;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

public class TestGeoTools {

  /**
     * GeoTIFF to PNG 변경
     * 
     * @param sourceFilePath
     * @param targetFilePath
     * @return boolean
     * @throws IOException
     */
  public static boolean convertGeoTiffToPng(String sourceFilePath, String targetFilePath) throws IOException {

    File file = new File(sourceFilePath);

    if (!file.exists()) {
      System.out.println("file not found");
      return false;
    }

    // AbstractGridFormat format = GridFormatFinder.findFormat(file);
    // System.out.println(format.getName());
    BufferedImage img = ImageIO.read(file);

    int width = img.getWidth();
    int height = img.getHeight();

    Raster raster = img.getData();
    int bands = raster.getNumBands();

    System.out.println("raster bands: " + bands);

    BufferedImage saveimage = null;
    WritableRaster dest = null;

    switch (bands) {
    case 1:
      saveimage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
      saveimage.createGraphics().drawImage(img, 0, 0, Color.white, null);
      break;
    case 3:
      // Create an identically-sized output raster
      dest = raster.createCompatibleWritableRaster();

      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          // Copy the pixel
          double[] pixel = new double[bands];
          pixel = raster.getPixel(x, y, pixel);
          if (pixel[0] > 255 && pixel[0] > 255 && pixel[0] > 255) {
            pixel[0] = 255;
            pixel[1] = 255;
            pixel[2] = 255;
          }
          dest.setPixel(x, y, pixel);
        }
      }

      // Save the raster back to the Image
      saveimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      saveimage.setData(dest);

      break;
    case 4:
      // Create an identically-sized output raster
      dest = raster.createCompatibleWritableRaster();

      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          // Copy the pixel
          double[] pixel = new double[bands];
          pixel = raster.getPixel(x, y, pixel);
          dest.setPixel(x, y, pixel);
        }
      }

      // Save the raster back to the Image
      saveimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      saveimage.setData(dest);

      break;
    }
    // Write the new file
    ImageIO.write(saveimage, "png", new File(targetFilePath));
    return true;

  }

  /**
     * GeoTIFF 에서 Extent값 가져옴
     * 
     * @param sourceFilePath
     * @return extent
     * @throws IOException
     */
  public static double[] getExtentFromGeoTiff(String sourceFilePath) throws IOException {

    File file = new File(sourceFilePath);
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    GridCoverage2DReader reader = format.getReader(file);
    GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
    Envelope env = coverage.getEnvelope();

    double minX = env.getLowerCorner().getOrdinate(0);
    double minY = env.getLowerCorner().getOrdinate(1);
    double maxX = env.getUpperCorner().getOrdinate(0);
    double maxY = env.getUpperCorner().getOrdinate(1);

    System.out.println("getGeoTiffExtent=" + coverage.getCoordinateReferenceSystem2D().getName().toString() + " " + coverage.getName() + ": " + minX + "," + minY + "  " + maxX + "," + maxY);

    double[] extent = new double[4];
    extent[0] = minX;
    extent[1] = minY;
    extent[2] = maxX;
    extent[3] = maxY;

    return extent;
  }

  /**
     * SHP파일에서 GeoJson가져옴
     * 
     * @param shpFilePath
     * @param charset
     * @param mapEPSG
     * @param bbox
     * @return geojson string
     * @throws IOException
     * @throws NoSuchAuthorityCodeException
     * @throws FactoryException
     * @throws TransformException
     * @throws CQLException
     */
  public static String getGeoJsonFromShp(String shpFilePath, String charset, String mapEPSG, String bbox)
  throws IOException,
  NoSuchAuthorityCodeException,
  FactoryException,
  TransformException,
  CQLException {

    // 파일 읽기
    File file = new File(shpFilePath);
    Map < String,
    Object > map = new HashMap < >();
    map.put("url", file.toURI().toURL());
    map.put("create spatial index", true);
    map.put("charset", charset); // encode

    System.out.println("charset::" + charset);

    DataStore dataStore = DataStoreFinder.getDataStore(map);
    String typeName = dataStore.getTypeNames()[0];
    FeatureSource < SimpleFeatureType,
    SimpleFeature > source = dataStore.getFeatureSource(typeName);

    CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);

    CoordinateReferenceSystem mapCRS = factory.createCoordinateReferenceSystem(mapEPSG); // CRS.decode(srsName);
    CoordinateReferenceSystem srcCRS = dataStore.getSchema(typeName).getCoordinateReferenceSystem();
    System.out.println("dataCRS.toWKT() :: " + srcCRS.toWKT());
    System.out.println("mapCRS.toWKT() :: " + mapCRS.toWKT());

    boolean lenient = true; // allow for some error due to different datums
    MathTransform transform = CRS.findMathTransform(mapCRS, srcCRS, lenient);

    String[] bbox_str = bbox.split(",");

    double[] param_bbox = new double[4];
    param_bbox[0] = Double.parseDouble(bbox_str[0]);
    param_bbox[1] = Double.parseDouble(bbox_str[1]);
    param_bbox[2] = Double.parseDouble(bbox_str[2]);
    param_bbox[3] = Double.parseDouble(bbox_str[3]);

    double[] srcProjec1 = {
      param_bbox[0],
      param_bbox[1]
    }; // easting, northing,
    double[] srcProjec2 = {
      param_bbox[2],
      param_bbox[3]
    }; // easting, northing,

    double[] dstProjec1 = {
      0,
      0
    };
    double[] dstProjec2 = {
      0,
      0
    };

    transform.transform(srcProjec1, 0, dstProjec1, 0, 1);
    transform.transform(srcProjec2, 0, dstProjec2, 0, 1);

    String filter_bbox = dstProjec1[0] + "," + dstProjec1[1] + "," + dstProjec2[0] + "," + dstProjec2[1];
    System.out.println("filter_bbox: " + filter_bbox);

    Filter filter = Filter.INCLUDE; // ECQL.toFilter("BBOX(THE_GEOM, 10,20,30,40)")
    if (!filter_bbox.isEmpty()) {
      filter = ECQL.toFilter("BBOX(the_geom," + filter_bbox + ")"); // ECQL.toFilter("BBOX(THE_GEOM,
      // 10,20,30,40)")
    }

    FeatureCollection < SimpleFeatureType,
    SimpleFeature > collection = source.getFeatures(filter);

    FeatureJSON featureJson = new FeatureJSON();
    StringWriter writer = new StringWriter();
    featureJson.writeFeatureCollection(collection, writer);

    String geojson = writer.toString();

    return geojson;
  }

}
반응형

'GIS' 카테고리의 다른 글

바로e맵 ol v4  (0) 2022.12.13
fabricjs + openlayers test  (0) 2019.12.19
proxy naver test  (0) 2019.12.12
how-to-get-map-units-to-find-current-scale-in-openlayers  (0) 2019.11.15
insert geometry type to geoserver meta table  (0) 2019.09.17
반응형

testfabricjs + openlayers test

 

fabricjs_test.zip
1.35MB

 

반응형
반응형
<%@page language = "java" pageEncoding = "utf-8" import = "java.io.*,java.net.URL,java.net.URLConnection,org.apache.commons.io.IOUtils" %>
<%
String GET_URL = request.getParameter("url");

URL tempURL = new URL(GET_URL);
byte[] bytes = null;
URLConnection conn = tempURL.openConnection();
bytes = IOUtils.toByteArray(conn.getInputStream());

System.out.println("bytes Length: " + bytes.length);

String THIS_URL = request.getRequestURL().toString();
String PROXY_URL = THIS_URL + "?url=";

System.out.println("GET_URL : " + GET_URL);
System.out.println("THIS_URL : " + THIS_URL);
System.out.println("PROXY_URL : " + PROXY_URL);

String contentType = conn.getContentType();
response.setContentType(contentType);

System.out.println("contentType: " + contentType);

if (GET_URL.contains("cur") || contentType.contains("image")) {
  out.clear();
  out = pageContext.pushBody();

  byte[] data = bytes;
  response.setHeader("Content-length", Integer.toString(data.length));
  response.setHeader("Accept-Ranges", "bytes");
  response.setHeader("Access-Control-Allow-Origin", "*");
  response.setContentType("text/plain;charset=UTF-8");

  response.getOutputStream().write(data, 0, data.length);
  response.getOutputStream().flush();

}
else {

  String output = new String(bytes);
  System.out.println("contentLength: " + output.length());

  output = output.replace("http://static.naver.net", PROXY_URL + "http://static.naver.net");
  output = output.replace("https://ssl.pstatic.net/static", PROXY_URL + "https://ssl.pstatic.net/static");
  output = output.replace("return\"http://\"+this.prefix+\"onetile\"", "return\"" + PROXY_URL + "http://\"+this.prefix+\"onetile\"");

  output = output.replace("_parse:function(t){var e=t.split", "_parse:function(t){t='" + GET_URL + "';var e=t.split");

  String temp = THIS_URL.replace(request.getScheme() + "://", "") + "?url=" + request.getScheme() + "://openapi.map.naver.com";
  output = output.replace("_sync:function(t,e){i.forEach(t,function(t){", "_sync:function(t,e){i.forEach(t,function(t){t=t.replace(location.hostname,'" + temp + "');");

  output = output.replace("&uri", "%26uri");
  output = output.replace("&useStyleMap", "%26useStyleMap");
  output = output.replace("&time", "%26time");
  output = output.replace("(F?\"https\":\"http\")", "(F?\"" + PROXY_URL + "https\":\"" + PROXY_URL + "http\")");
  output = output.replace("&\")+s.callbackname", "%26\")+s.callbackname");

  output = output.replace("!u.test(e)", "u.test(e)");

  output = output.replace("e=\"\";", "e=\"\";e=decodeURIComponent(e);e=e.split('url')[1];");
  output = output.replace("http://rts1.map.naver.net", PROXY_URL + "http://rts1.map.naver.net");

  //output = output.replace("removeDOMListener:function(t,n,o){", "removeDOMListener:function(t,n,o){console.log(t);console.log(i);");

  out.print(output);
}

System.out.println("");
%>
반응형
반응형
var INCHES_PER_UNIT = { 'm': 39.37, 'dd': 4374754 };
var DOTS_PER_INCH = 72;

/** * @param {number} resolution Resolution.
* @param {string} units Units
* @param {boolean=} opt_round Whether to round the scale or not.
* @return {number} Scale */
var getScaleFromResolution = function(resolution, units, opt_round) {
var scale = INCHES_PER_UNIT[units] * DOTS_PER_INCH * resolution;
  if (opt_round) {
    scale = Math.round(scale);
  }
  return scale;
};

var units = map.getView().getProjection().getUnits();
var INCHES_PER_UNIT = {
  'm': 39.37,
  'dd': 4374754
};
var DOTS_PER_INCH = 72;

/**
 * @param {number} resolution Resolution.
 * @param {string} units Units
 * @param {boolean=} opt_round Whether to round the scale or not.
 * @return {number} Scale
 */
var getScaleFromResolution = function(resolution, units, opt_round) {
  var scale = INCHES_PER_UNIT[units] * DOTS_PER_INCH * resolution;
  if (opt_round) {
    scale = Math.round(scale);
  }
  return scale;
};


function mapScale (dpi) {
    var unit = map.getView().getProjection().getUnits();
    var resolution = map.getView().getResolution();
    var inchesPerMetre = 39.37;

    return resolution * ol.proj.METERS_PER_UNIT[unit] * inchesPerMetre * dpi;
}

 

 

 

https://gis.stackexchange.com/questions/242424/how-to-get-map-units-to-find-current-scale-in-openlayers

반응형

'GIS' 카테고리의 다른 글

fabricjs + openlayers test  (0) 2019.12.19
proxy naver test  (0) 2019.12.12
insert geometry type to geoserver meta table  (0) 2019.09.17
shp to oracle  (0) 2019.09.02
proj4 transform java  (0) 2019.08.25
반응형

SELECT CASE
    WHEN X.GTYPE = 1 THEN 'POINT' 
    WHEN X.GTYPE  = 2 THEN 'LINE' 
    WHEN X.GTYPE  = 3 THEN 'POLYGON' 
    WHEN X.GTYPE  = 4 THEN 'COLLECTION' 
    WHEN X.GTYPE  = 5 THEN 'MULTIPOINT' 
    WHEN X.GTYPE  = 6 THEN 'MULTILINE' 
    WHEN X.GTYPE  = 7 THEN 'MULTIPOLYGON' 
        ELSE 'GEOMETRY' END GTYPE
    FROM 
        (SELECT MAX(A.GEOMETRY.GET_GTYPE()) GTYPE FROM TGE_B_ADM_EMD_A A WHERE ROWNUM<1000) X 
;

반응형

'GIS' 카테고리의 다른 글

proxy naver test  (0) 2019.12.12
how-to-get-map-units-to-find-current-scale-in-openlayers  (0) 2019.11.15
shp to oracle  (0) 2019.09.02
proj4 transform java  (0) 2019.08.25
PostGIS에 한국 좌표계 추가  (0) 2019.08.22
반응형

// shp to oracle 
java -classpath .\ojdbc6.jar;.\sdoutl.jar;.\sdoapi.jar oracle.spatial.util.SampleShapefileToJGeomFeature 
-h 192.168.252.130 -p 1521 -s orcl -u test -d 1111 -f D:\temp2\test\TGE_T_GGS_P -r 3857 -g geometry -i fid -t TGE_T_GGS_P


// geometry 인덱스 생성
CREATE INDEX TGE_T_GGS_P_GEOM_IDX ON TGE_T_GGS_P (GEOMETRY) INDEXTYPE IS MDSYS.SPATIAL_INDEX;

// fid 유니크 인덱스 생성
CREATE UNIQUE INDEX TGE_T_GGS_P_UIDX ON TGE_T_GGS_P( FID );


SELECT * FROM MDSYS.USER_SDO_GEOM_METADATA;





ShpToOracle.zip
9.50MB

반응형

'GIS' 카테고리의 다른 글

how-to-get-map-units-to-find-current-scale-in-openlayers  (0) 2019.11.15
insert geometry type to geoserver meta table  (0) 2019.09.17
proj4 transform java  (0) 2019.08.25
PostGIS에 한국 좌표계 추가  (0) 2019.08.22
openlayers 5 bbox  (0) 2019.08.21
반응형
package test;

import org.osgeo.proj4j.CRSFactory;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.osgeo.proj4j.CoordinateTransform;
import org.osgeo.proj4j.CoordinateTransformFactory;
import org.osgeo.proj4j.ProjCoordinate;

/*
 * maven import
 *  
  <dependency>
  <groupId>org.osgeo</groupId>
  <artifactId>proj4j</artifactId>
  <version>0.1.0</version>
</dependency> 

 */

public class Main {

  public static void main(String[] args) {
    ProjCoordinate trans = transform(14203089.275873486, 4414526.262702693);
    System.out.format("%s, %s", trans.x, trans.y);
  }

  public static ProjCoordinate transform(Double x, Double y) {
      
    CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
    CRSFactory csFactory = new CRSFactory();
    CoordinateReferenceSystem GOOGLE = csFactory.createFromParameters("EPSG:3857", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs");
    CoordinateReferenceSystem WGS84 = csFactory.createFromParameters("WGS84", "+proj=longlat +datum=WGS84 +no_defs");
    CoordinateTransform trans = ctFactory.createTransform(GOOGLE, WGS84);
    ProjCoordinate p = new ProjCoordinate();
    ProjCoordinate p2 = new ProjCoordinate();
    p.x = x;
    p.y = y;
    return trans.transform(p, p2);

  }

}
반응형

'GIS' 카테고리의 다른 글

insert geometry type to geoserver meta table  (0) 2019.09.17
shp to oracle  (0) 2019.09.02
PostGIS에 한국 좌표계 추가  (0) 2019.08.22
openlayers 5 bbox  (0) 2019.08.21
geoserver+oracle 사용시 unique index, geometry metadata 쿼리 작업  (0) 2019.08.18
반응형

출처 https://www.osgeo.kr/205

 

 

 

postgis_korea_epsg_towgs84.sql
0.06MB

 

 

반응형

'GIS' 카테고리의 다른 글

shp to oracle  (0) 2019.09.02
proj4 transform java  (0) 2019.08.25
openlayers 5 bbox  (0) 2019.08.21
geoserver+oracle 사용시 unique index, geometry metadata 쿼리 작업  (0) 2019.08.18
oracle spatial 에 한국좌표계 정보 추가하기  (0) 2019.08.09
반응형
function drawbbox() {
    var bbox = map.getView().calculateExtent();
    var coord = [[
        [bbox[0], bbox[1]],
        [bbox[0], bbox[3]],
        [bbox[2], bbox[3]],
        [bbox[2], bbox[1]],
        [bbox[0], bbox[1]]
    ]];

    var geojsonObject = {
        'type': 'FeatureCollection',
        'crs': {
            'type': 'name',
            'properties': {
                'name': 'EPSG:3857'
            }
        },
        'features': [{
            'type': 'Feature',
            'geometry': {
                'type': 'Polygon',
                'coordinates': coord
            }
        }]
    };

    var bboxSource = new ol.source.Vector({
        features: new ol.format.GeoJSON().readFeatures(geojsonObject)
    });

    var bbox = new ol.layer.Vector({
        name: 'Select',
        source: bboxSource,
        style: new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: 'blue'
            }),
            fill: new ol.style.Fill({
                color: [0, 0, 255, 0.05]
            })
        })
    });
    map.addLayer(bbox);
}
반응형
반응형

참고,

https://docs.geoserver.org/stable/en/user/data/database/primarykey.html#metadata-table-description

https://docs.geoserver.org/latest/en/user/data/database/oracle.html#using-the-geometry-metadata-table

 

 

 

c# project

 

release

Release.zip
3.02MB

반응형

'GIS' 카테고리의 다른 글

PostGIS에 한국 좌표계 추가  (0) 2019.08.22
openlayers 5 bbox  (0) 2019.08.21
oracle spatial 에 한국좌표계 정보 추가하기  (0) 2019.08.09
oracle import shp  (0) 2019.08.08
Using OGR2OGR to re-project a shape file  (0) 2019.08.07
반응형

oracle_korean_cs_srs.txt
0.01MB

첨부파일 확인

 

--구글 좌표계 900913, 3857
--서부원점(bassel)- EPSG:5173
--중부원점(bassel)- EPSG:5174
--제주원점(bassel)- EPSG:5175
--동부원점(bassel)- EPSG:5176
--동해울릉원점(bassel)- EPSG:5177
--UTM-K(Bessel 1841) EPSG:5178
--UTM-K(GRS80) EPSG: 5179
--서부원점(GRS80) EPSG: 5180 (False_Easting: 200000.0 , False_Northing: 500000.0)
--중부원점(GRS80) EPSG: 5181 (False_Easting: 200000.0 , False_Northing: 500000.0)
--제주원점(GRS80) EPSG: 5182 (False_Easting: 200000.0 , False_Northing: 550000.0)
--동부원점(GRS80) EPSG: 5183 (False_Easting: 200000.0 , False_Northing: 500000.0)
--동해울릉원점(GRS80) EPSG: 5184 (False_Easting: 200000.0 , False_Northing: 500000.0)
--서부원점_2010(GRS80)  EPSG: 5185 (False_Easting: 200000.0 , False_Northing: 600000.0)
--중부원점_2010(GRS80) EPSG:5186 (False_Easting: 200000.0 , False_Northing: 600000.0)
--동부원점_2010(GRS80)-EPSG:5187  (False_Easting: 200000.0 , False_Northing: 600000.0)
--동해(울릉)원점_2010(GRS80)-EPSG:5188  (False_Easting: 200000.0 , False_Northing: 600000.0)

 

반응형

'GIS' 카테고리의 다른 글

openlayers 5 bbox  (0) 2019.08.21
geoserver+oracle 사용시 unique index, geometry metadata 쿼리 작업  (0) 2019.08.18
oracle import shp  (0) 2019.08.08
Using OGR2OGR to re-project a shape file  (0) 2019.08.07
fwtools로 tif to ecw 변환  (0) 2015.01.23
반응형

oracle import shp

 

Oracle Map Builder 프로그램 사용 

https://www.oracle.com/technetwork/middleware/mapviewer/downloads/index-100641.html

 

  

map_builder.zip
2.68MB
map_builder.z01
19.53MB
map_builder.z02
19.53MB

 

반응형
반응형

Using OGR2OGR to re-project a shape file 

 

 

The syntax for this is :

ogr2ogr -f "ESRI Shapefile" original.shp wgs84.shp -s_srs EPSG:27700 -t_srs EPSG:4326

 

 

반응형

'GIS' 카테고리의 다른 글

oracle spatial 에 한국좌표계 정보 추가하기  (0) 2019.08.09
oracle import shp  (0) 2019.08.08
fwtools로 tif to ecw 변환  (0) 2015.01.23
gdal2tiles using  (0) 2014.06.11
gdal oracle export/import shp  (0) 2014.03.10
반응형

fwtools-2.4.7    http://fwtools.maptools.org/  



C:\geo>gdal_translate -of ECW spcs83ft.tif spcs83ft.ecw
Input file size is 516, 516
0...10...20...30...40...50...60...70...80...90...100 - done.



반응형

'GIS' 카테고리의 다른 글

oracle import shp  (0) 2019.08.08
Using OGR2OGR to re-project a shape file  (0) 2019.08.07
gdal2tiles using  (0) 2014.06.11
gdal oracle export/import shp  (0) 2014.03.10
geotiff gdal merged and tiles  (0) 2014.02.28

+ Recent posts