« 電子国土ラボ | メイン | タイリングされた地図のコンテナの例 »

電子国土SVG Mapコンテナビルダー

電子国土ラボ が公開されました。電子国土SVGデータは、30秒区切りのタイルデータになっています。そのため、このデータはタイリングして使用すると便利です。

そこで、タイリングされた地図データの仕様に基づいた、コンテナSVGファイルを生成するプログラムを公開します。

ダウンロードした電子国土データのディレクトリを指定すると、そのディレクトリ内にある地図タイルデータをタイリングするコンテナSVGデータを生成します。

LGPLに基づいてご使用ください。

MakeCJContainer.java

// The basic Cyber Japan SVG Map mesh data container for tiling
//
// Copyright (C) 2007 by Satoru Takagi All rights reserved.
//  http://www.svg-map.com/
//
// Usage : java MakeCJContainer SearchDirectory
// Output: SearchDirectory.svg
//
// =============================================================================
//
// This software is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by  the  Free
// Software Foundation; either version 2.1 of the License, or (at  your  option)
// any later version.
//
// This library is distributed in the hope that it will be  useful,  but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for  more
// details.
//
// You should have received a copy of the  GNU  Lesser  General  Public  License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =============================================================================
import java.io.*;
import java.util.*;

public class MakeCJContainer {
public final static double svgMeshHeight = 400.0; // set mesh Height for SVG

public static double svgMeshWidth;
    public static String target;
static boolean firstTile = false;
static double tA, tB , tC , tD , tE , tF; // transform matrix for CRS

// Main
    public static void main( String argv[] ){
        try {
   // Prepare an output SVG Map file
   FileOutputStream osFile = new FileOutputStream( argv[0] + ".svg" );
   Writer fos = new BufferedWriter(new OutputStreamWriter( osFile , "UTF-8" ));

            MakeCJContainer.target = ".svg";
            MakeCJContainer top
                = new MakeCJContainer( new File( "."+ File.separator + argv[0] + File.separator) , fos );
   fos.close();
        }
        catch( ArrayIndexOutOfBoundsException e ) {  // Parameter error
            System.err.println("Usage:java MakeCJContainer searchname");
            System.exit(-1);
        }
        catch( Exception e ) {   // Other Errors
            System.err.println("Error....");
         e.printStackTrace();
            System.exit(-1);
        }
    }

// Constructor
    public MakeCJContainer( File dir ,  Writer out ) throws Exception {
    
        try {
         searchSubDirs( dir , out );
        }
     catch( Exception e ) {
            throw e;
        }
     out.write("</svg>\n");
    }

// Generation of image element of SVG Map mesh
    public void writeImageElement( File aFile ,  Writer out ) {
     String name;
     int mStart , mEnd;
  if( aFile.getName().indexOf( target ) >= 0 ){
   name = aFile.getPath();
   mStart = name.lastIndexOf(File.separator) + 1;
   mEnd = name.indexOf( "-all" );
   try {
    CyberJpMesh mesh = new CyberJpMesh( name.substring(mStart , mEnd));
   
    if (firstTile==false){
     printSvgHeader( mesh.longitude , mesh.latitude , CyberJpMesh.span , CyberJpMesh.span , out);
     firstTile=true;
    }
    calcTransform( mesh.longitude , mesh.latitude + CyberJpMesh.span );
       out.write("<image xlink:href=\"" + name.replace('\\' , '/') +"\" "
    + "y=\"" + transY + "\" " + "x=\"" + transX + "\" "
    + "width=\"" + svgMeshWidth + "\" " + "height=\"" + svgMeshHeight + "\" />\n");
   } catch (Exception e ) {
   
   }
  }
    }

// Recurrent search for subdirectory
    public void searchSubDirs(File dir ,  Writer out ) throws Exception {
     File[] files;
     String[] names;
     names = dir.list();
     int fileLength = names.length;
     files = new File[ fileLength ];
        try {
         for( int i=0; i< fileLength; i++ ){
          files[i] = new File( dir.getPath() + File.separator + names[i] );
              if( files[i].isDirectory() ) {
              searchSubDirs( files[i] , out );
             } else {
              writeImageElement( files[i] , out);
             }
         }
        }
        catch( Exception e ) {
            throw e;
        }
    
    }


// Coordinate Trnasformer
private double transX , transY;

private void calcTransform( double x , double y){
  transX = tA * x + tC * y + tE;
  transY = tB * x + tD * y + tF;
}


// Prepare transform matrix for CRS using first mesh and write SVG header.
public void printSvgHeader(double x , double y , double w , double h ,  Writer out) throws Exception{
  tD = - svgMeshHeight / h;
  svgMeshWidth =  svgMeshHeight * Math.cos( y * Math.PI / 180.0 ) * w / h ;
  tA = - tD * Math.cos( y * Math.PI / 180.0 );
  tB = 0.0;
  tC = 0.0;
 
  tE = - tA * x;
  tF = - tD * ( y + h );
 
 
  out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  out.write("<svg  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"" + 0.0 + " " + 0.0 + " " + w * tA + " " + (- h * tD) + "\">\n");
  out.write("<metadata>\n");
  out.write("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:crs=\"http://www.ogc.org/crs\" xmlns:svg=\"http://www.w3.org/2000/svg\">\n");
  out.write("<rdf:Description>");
  out.write("<crs:CoordinateReferenceSystem rdf:resource=\"http://purl.org/crs/84\"  svg:transform=\"matrix(" + tA + "," + tB + "," + tC + "," + tD + "," + tE + "," + tF + ")\" />\n");
  out.write("</rdf:Description>\n");
  out.write("</rdf:RDF>\n");
  out.write("</metadata>\n");
}

}

CyberJpMesh.java

// 電子国土SVGのメッシュコードを入出力します
// 2007/04/06 Satoru Takagi

import java.util.*;
import java.io.*;

public class CyberJpMesh{

public String mesh , latMesh , longMesh;
public int latNo , longNo;
public double latitude , longitude;

public static double span = 30.0 / (60.0 * 60.0); // 30sec

public static void main( String argv[] ) {
  if (argv.length == 2 ){
   CyberJpMesh jm = new CyberJpMesh(Double.parseDouble(argv[0]) , Double.parseDouble(argv[1]));
   System.out.println( "mesh3:" + jm );
  } else {
   CyberJpMesh jm = new CyberJpMesh( argv[0]);
   System.out.println( "lat:" + jm.latitude + " long:" + jm.longitude );
  }
}

public CyberJpMesh(double lati , double longi){
  latitude = lati;
  longitude = longi;
 
  latNo = (int)(latitude * 60.0 * 60.0 * 100.0);
  longNo = (int)(longitude * 60.0 * 60.0 * 100.0);
 
  latMesh = Integer.toString(latNo);
  longMesh = Integer.toString(longNo);
  mesh = longMesh + "-" + latMesh;
 
}

public CyberJpMesh(String meshNo){
  mesh = meshNo;
  int delim = mesh.indexOf("-");
  if ( delim < 0 ) {
   throw new NumberFormatException();
  }
  longMesh=mesh.substring(0,delim);
  latMesh=mesh.substring(delim+1);
 
  latNo = Integer.parseInt(latMesh);
  longNo = Integer.parseInt(longMesh);
 
  latitude = (double)latNo / (60.0 * 60.0 * 100);
  longitude = (double)longNo / (60.0 * 60.0 * 100);
 
}

public String toString(){
  return (mesh);
}

}

トラックバック

このページのトラックバックURL:
http://www.typepad.jp/t/trackback/229612/6936687

このページへのトラックバック一覧 電子国土SVG Mapコンテナビルダー:

» フリーソフトのダウンロードコミュ!使えるフリーソフトやスクリプトを紹介 トラックバック フリーソフトのダウンロードコミュ!使えるフリーソフトやスクリプトを紹介
DVDのコピー [続きを読む]

検索

注目エントリー

2008年8月

          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

最近のトラックバック