首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >生成TomTom全球定位系统poi数据的Java库

生成TomTom全球定位系统poi数据的Java库
EN

Stack Overflow用户
提问于 2011-08-16 20:40:40
回答 1查看 1.1K关注 0票数 5

我想知道是否有任何Java库可以为Tomtom导航设备生成poi-data (通常该文件具有.ov2扩展名)。

我使用Tomtom的Tomtom makeov2.exe util,但它不稳定,似乎不再支持。

EN

回答 1

Stack Overflow用户

发布于 2011-08-24 00:46:26

我找不到一个可以写的库,尽管我找到了这个读取.ov2文件的类:

代码语言:javascript
复制
package readers;

import java.io.FileInputStream;
import java.io.IOException;

public class OV2RecordReader {

    public static String[] readOV2Record(FileInputStream inputStream){
        String[] record = null;
        int b = -1;
        try{
            if ((b = inputStream.read())> -1) {
                // if it is a simple POI record
                if (b == 2) {
                    record = new String[3];
                    long total = readLong(inputStream);

                    double longitude = (double) readLong(inputStream) / 100000.0;
                    double latitude = (double) readLong(inputStream) / 100000.0;

                    byte[] r = new byte[(int) total - 13];
                    inputStream.read(r);

                    record[0] = new String(r);
                    record[0] = record[0].substring(0,record[0].length()-1);
                    record[1] = Double.toString(latitude);
                    record[2] = Double.toString(longitude);
                }
                //if it is a deleted record
                else if(b == 0){
                    byte[] r = new byte[9];
                    inputStream.read(r);
                }
                //if it is a skipper record
                else if(b == 1){
                    byte[] r = new byte[20];
                    inputStream.read(r);
                }
                else{
                    throw new IOException("wrong record type");
                }
            }
            else{
                return null;
            }
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return record;
    }

    private static long readLong(FileInputStream is){
        long res = 0;
        try{
            res = is.read();
            res += is.read() <<8;
            res += is.read() <<16;
            res += is.read() <<24;
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return res;
    }
}

我还找到了用来编写文件的PHP代码:

代码语言:javascript
复制
<?php
$csv = file("File.csv");
$nbcsv = count($csv);
$file = "POI.ov2";
$fp = fopen($file, "w");
for ($i = 0; $i < $nbcsv; $i++) {
    $table = split(",", chop($csv[$i]));
    $lon = $table[0];
    $lat = $table[1];
    $des = $table[2];
    $TT = chr(0x02).pack("V",strlen($des)+14).pack("V",round($lon*100000)).pack("V",round($lat*100000)).$des.chr(0x00);
    @fwrite($fp, "$TT");
}
fclose($fp);

我不确定如何像PHP函数那样编写Java类(或扩展上面的类)来编写文件,但您也许能够深入了解文件是如何编码的。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7078332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档