• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Osmformat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.openstreetmap.osmosis.osmbinary.Osmformat的典型用法代码示例。如果您正苦于以下问题:Java Osmformat类的具体用法?Java Osmformat怎么用?Java Osmformat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Osmformat类属于org.openstreetmap.osmosis.osmbinary包,在下文中一共展示了Osmformat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseNodes

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseNodes(List<Osmformat.Node> pbfNodes) {
	for (Osmformat.Node pbfNode : pbfNodes) {
		Map<String, String> tags = new HashMap<String, String>();
		for (int j = 0; j < pbfNode.getKeysCount(); j++) {
			tags.put(getStringById(pbfNode.getKeys(j)), getStringById(pbfNode.getVals(j)));
		}
		Node osmNode = null;
		long id = pbfNode.getId();
		double latf = parseLat(pbfNode.getLat()), lonf = parseLon(pbfNode.getLon());

     	boolean visible = true;
     	
		if (pbfNode.hasInfo()) {
			Osmformat.Info info = pbfNode.getInfo();
			if (info.hasVisible()) visible = info.getVisible();
			osmNode = new Node(OsmElementType.NODE, id, info.getUid(), getStringById(info.getUserSid()),
					getDate(info), (int) info.getChangeset(), (short) info.getVersion(), visible, tags,
					(info.getVisible() ? new Coordinate(lonf, latf) : null));
		}
		osmDataConsumer.process(osmNode);
	}
}
 
开发者ID:SGroe,项目名称:vgi-analytics-framework,代码行数:24,代码来源:OsmPbfParser.java


示例2: parse

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void parse(Osmformat.HeaderBlock block) {
	for (String s : block.getRequiredFeaturesList()) {
		if (s.equals("OsmSchema-V0.6")) {
			continue;
		}
		if (s.equals("DenseNodes")) {
			continue;
		}
		if (s.equals("HistoricalInformation")) {
			continue;
		}
		log.error("Cannot parse file");
		System.exit(0);
	}
}
 
开发者ID:SGroe,项目名称:vgi-analytics-framework,代码行数:17,代码来源:OsmPbfParser.java


示例3: parseNodes

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseNodes(List<Osmformat.Node> nodes) {
	for (Osmformat.Node n : nodes) {
		Node n2 = new Node();
		Primitive p = getPrimitive(n.getInfo());
		p.setId(n.getId());
		p.setTags(getTags(n.getKeysList(), n.getValsList()));
		n2.setCommon(p);
		n2.setLatitude(parseLat(n.getLat()));
		n2.setLongitude(parseLon(n.getLon()));
		try {
			nodeWriter.append(n2);
		}
		catch (IOException e) {
			LOGGER.error("Unable to write node", e);
		}
	}
}
 
开发者ID:ngageoint,项目名称:geowave-osm,代码行数:19,代码来源:OsmPbfParser.java


示例4: parseWays

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseWays(List<Osmformat.Way> ways) {
	for (Osmformat.Way w : ways) {
		Way w2 = new Way();
		Primitive p = getPrimitive(w.getInfo());
		p.setId(w.getId());
		p.setTags(getTags(w.getKeysList(), w.getValsList()));
		w2.setCommon(p);

		long lastRef = 0;
		List<Long> nodes = new ArrayList<>(w.getRefsCount());
		for (Long ref : w.getRefsList()) {
			lastRef+= ref;
			nodes.add(lastRef);
		}
		w2.setNodes(nodes);

		try {
			wayWriter.append(w2);
		}
		catch (IOException e) {
			LOGGER.error("Unable to write way", e);
		}
	}
}
 
开发者ID:ngageoint,项目名称:geowave-osm,代码行数:26,代码来源:OsmPbfParser.java


示例5: endBlock

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
/** We always add one primitive group of less that 8k elements to each primitive block. */
private void endBlock () {
    if (nEntitiesInBlock > 0) {
        if (currEntityType == OSMEntity.Type.NODE) {
            primitiveGroupBuilder.setDense(denseNodesBuilder);
        }
        // Pass the block off to the compression/writing thread
        try {
            Osmformat.PrimitiveBlock primitiveBlock = Osmformat.PrimitiveBlock.newBuilder()
                    .setStringtable(stringTable.toBuilder()).addPrimitivegroup(primitiveGroupBuilder).build();
            synchronousQueue.put(primitiveBlock);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:17,代码来源:PBFOutput.java


示例6: writeBegin

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void writeBegin() throws IOException {

    LOG.info("Writing PBF format...");

    // Write out a header block
    Osmformat.HeaderBlock.Builder builder = Osmformat.HeaderBlock.newBuilder();
    builder.addRequiredFeatures("DenseNodes").setWritingprogram("Vanilla Extract").build();
    if (timestamp > 0) {
        builder.setOsmosisReplicationTimestamp(timestamp);
    }
    writeOneBlob(builder.build());

    // Start another thread that will handle compression and writing in parallel.
    writerThread = new Thread(this);
    writerThread.start();

}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:19,代码来源:PBFOutput.java


示例7: writeWay

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void writeWay(long id, Way way) throws IOException {

    checkBlockTransition(OSMEntity.Type.WAY);
    Osmformat.Way.Builder builder = Osmformat.Way.newBuilder().setId(id);

    /* Tags */
    if (way.tags != null) {
        for (OSMEntity.Tag tag : way.tags) {
            if (tag.value == null) tag.value = "";
            builder.addKeys(stringTable.getCode(tag.key));
            builder.addVals(stringTable.getCode(tag.value));
        }
    }

    /* Node References */
    long prevNodeRef = 0;
    for (long ref : way.nodes) {
        builder.addRefs(ref - prevNodeRef); // delta-coded node references
        prevNodeRef = ref;
    }

    /* TODO Should we trigger the build here or just call with the builder? */
    primitiveGroupBuilder.addWays(builder.build());

}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:27,代码来源:PBFOutput.java


示例8: run

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
/** Runnable interface implementation that compresses and writes output blocks asynchronously. */
@Override
public void run() {
    while (true) {
        try {
            Osmformat.PrimitiveBlock block = synchronousQueue.take(); // block until work is available
            if (block.getPrimitivegroupCount() == 0) {
                break; // a block with no primitive groups tells the writer thread to shut down.
            }
            writeOneBlob(block);
        } catch (InterruptedException ex) {
            LOG.error("Block writer thread was interrupted while waiting for work.");
            break;
        }
    }
    try {
        downstream.flush();
        downstream.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:23,代码来源:PBFOutput.java


示例9: parseNodes

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
/** Note that in many PBF files this function is never called because all nodes are dense. */
@Override
protected void parseNodes(List<Osmformat.Node> nodes) {
    try {
        for (Osmformat.Node n : nodes) {
            if (nodeCount++ % 10000000 == 0) {
                LOG.info("node {}", human(nodeCount));
            }
            Node node = new Node(parseLat(n.getLat()), parseLon(n.getLon()));
            for (int k = 0; k < n.getKeysCount(); k++) {
                String key = getStringById(n.getKeys(k));
                String val = getStringById(n.getVals(k));
                if (retainTag(key)) node.addTag(key, val);
            }
            entitySink.writeNode(n.getId(), node);
        }
    } catch (IOException ex) {
        LOG.error("An I/O exception occurred in the OSM entity sink.");
        ex.printStackTrace();
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:22,代码来源:PBFInput.java


示例10: parse

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void parse(Osmformat.HeaderBlock block) {
    for (String s : block.getRequiredFeaturesList()) {
        if (s.equals("OsmSchema-V0.6")) {
            continue; // We can parse this.
        }
        if (s.equals("DenseNodes")) {
            continue; // We can parse this.
        }
        throw new IllegalStateException("File requires unknown feature: " + s);
    }
    if (block.hasOsmosisReplicationTimestamp()) {
        long timestamp = block.getOsmosisReplicationTimestamp();
        LOG.info("PBF file has a replication timestamp of {}", Instant.ofEpochSecond(timestamp));
        entitySink.setReplicationTimestamp(timestamp);
    } else {
        LOG.info("PBF file has no replication timestamp.");
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:20,代码来源:PBFInput.java


示例11: processWays

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
private void processWays( List<Osmformat.Way> ways, BPbfFieldDecoder fieldDecoder )
{
    for (Osmformat.Way way : ways)
    {
        Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder);

        // Build up the list of way nodes for the way. The node ids are
        // delta encoded meaning that each id is stored as a delta against
        // the previous one.
        long nodeId = 0;
        LongList wayNodes = new LongList( 16 );
        for (long nodeIdOffset : way.getRefsList())
        {
            nodeId += nodeIdOffset;
            wayNodes.add(nodeId);
        }

        parser.addWay( way.getId(), tags, wayNodes );
    }
}
 
开发者ID:abrensch,项目名称:brouter,代码行数:21,代码来源:BPbfBlobDecoder.java


示例12: parseNodes

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseNodes(
		List<Osmformat.Node> nodes ) {
	for (Osmformat.Node n : nodes) {
		Node n2 = new Node();
		Primitive p = getPrimitive(n.getInfo());
		p.setId(n.getId());
		p.setTags(getTags(
				n.getKeysList(),
				n.getValsList()));
		n2.setCommon(p);
		n2.setLatitude(parseLat(n.getLat()));
		n2.setLongitude(parseLon(n.getLon()));
		try {
			nodeWriter.append(n2);
		}
		catch (IOException e) {
			LOGGER.error(
					"Unable to write node",
					e);
		}
	}
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:24,代码来源:OsmPbfParser.java


示例13: getPrimitive

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
private Primitive getPrimitive(
		Osmformat.Info info ) {
	Primitive p = new Primitive();
	p.setVersion((long) info.getVersion());
	p.setTimestamp(info.getTimestamp());
	p.setUserId((long) info.getUid());
	try {
		p.setUserName(getStringById(info.getUid()));
	}
	catch (Exception ex) {
		LOGGER.warn(
				"Error, input file doesn't contain a valid string table for user id: " + info.getUid(),
				ex);
		p.setUserName(String.valueOf(info.getUid()));
	}
	p.setChangesetId(info.getChangeset());
	p.setVisible(info.getVisible());
	return p;
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:20,代码来源:OsmPbfParser.java


示例14: parseRelations

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseRelations(List<Osmformat.Relation> pbfRelations) {
    for (Osmformat.Relation pbfRelation : pbfRelations) {
    	Map<String, String> tags = new HashMap<String, String>();
        for (int j = 0; j < pbfRelation.getKeysCount(); j++) {
            tags.put(getStringById(pbfRelation.getKeys(j)), getStringById(pbfRelation.getVals(j)));
        }
        
        long lastMemberId = 0;
        List<RelationMember> nodes = new ArrayList<RelationMember>();
        for (int j = 0; j < pbfRelation.getMemidsCount(); j++) {
            long memberId = lastMemberId + pbfRelation.getMemids(j);
            lastMemberId = memberId;
            OsmElementType elementType = OsmElementType.UNKOWN;

            if (pbfRelation.getTypes(j) == Osmformat.Relation.MemberType.NODE) {
                elementType = OsmElementType.NODE;
            } else if (pbfRelation.getTypes(j) == Osmformat.Relation.MemberType.WAY) {
                elementType = OsmElementType.WAY;
            } else if (pbfRelation.getTypes(j) == Osmformat.Relation.MemberType.RELATION) {
                elementType = OsmElementType.RELATION;
            }
            
            nodes.add(new RelationMember(memberId, elementType, getStringById(pbfRelation.getRolesSid(j))));
        }

        boolean visible = true;
        
        Relation osmRelation = null;
        if (pbfRelation.hasInfo()) {
            Osmformat.Info info = pbfRelation.getInfo();
            if (info.hasVisible()) visible = info.getVisible();
            
            osmRelation = new Relation(OsmElementType.RELATION, pbfRelation.getId(), info.getUid(), getStringById(info.getUserSid()), getDate(info), (int) info.getChangeset(), (short) info.getVersion(), visible, tags, nodes);
        }
        osmDataConsumer.process(osmRelation);
    }
}
 
开发者ID:SGroe,项目名称:vgi-analytics-framework,代码行数:39,代码来源:OsmPbfParser.java


示例15: parseRelations

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
protected void parseRelations(List<Osmformat.Relation> rels) {
	for (Osmformat.Relation r : rels){
		Relation r2 = new Relation();
		Primitive p = getPrimitive(r.getInfo());
		p.setId(r.getId());
		p.setTags(getTags(r.getKeysList(), r.getValsList()));
		r2.setCommon(p);

		List<RelationMember> members = new ArrayList<>(r.getRolesSidCount());

		for (int i = 0; i < r.getRolesSidCount(); i++){
			RelationMember rm = new RelationMember();
			rm.setMember(r.getMemids(i));
			rm.setRole(getStringById(r.getRolesSid(i)));
			switch (r.getTypes(i).toString()){
				case "NODE": {
					rm.setMemberType(MemberType.NODE);
					break;
				}
				case "WAY": {
					rm.setMemberType(MemberType.WAY);
					break;
				}
				case "RELATION" : {
					rm.setMemberType(MemberType.RELATION);
					break;
				}
			}

		}
		r2.setMembers(members);
		try {
			relationWriter.append(r2);
		}
		catch (IOException e) {
			LOGGER.error("Unable to write relation", e);
		}
	}
}
 
开发者ID:ngageoint,项目名称:geowave-osm,代码行数:41,代码来源:OsmPbfParser.java


示例16: getPrimitive

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
private Primitive getPrimitive(Osmformat.Info info){
	Primitive p = new Primitive();
	p.setVersion((long)info.getVersion());
	p.setTimestamp(info.getTimestamp());
	p.setUserId((long) info.getUid());
	try {
		p.setUserName(getStringById(info.getUid()));
	} catch (Exception ex) {
		LOGGER.warn("Error, input file doesn't contain a valid string table for user id: " + info.getUid());
		p.setUserName(String.valueOf(info.getUid()));
	}
		p.setChangesetId(info.getChangeset());
		p.setVisible(info.getVisible());
	return p;
}
 
开发者ID:ngageoint,项目名称:geowave-osm,代码行数:16,代码来源:OsmPbfParser.java


示例17: beginBlock

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
/** Reset the inter-entity delta coding values and set up a new block. */
private void beginBlock(OSMEntity.Type eType) throws IOException {
    prevId = prevFixedLat = prevFixedLon = nEntitiesInBlock = 0;
    stringTable.clear();
    primitiveGroupBuilder = Osmformat.PrimitiveGroup.newBuilder();
    if (eType == OSMEntity.Type.NODE) {
        denseNodesBuilder = Osmformat.DenseNodes.newBuilder();
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:10,代码来源:PBFOutput.java


示例18: writeOneBlob

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
/** @param block is either a PrimitiveBlock or a HeaderBlock */
private void writeOneBlob(GeneratedMessageLite block) {

    // FIXME lotsa big copies going on here

    String blobTypeString;
    if (block instanceof Osmformat.HeaderBlock) {
        blobTypeString = "OSMHeader";
    } else if (block instanceof Osmformat.PrimitiveBlock) {
        blobTypeString = "OSMData";
    } else {
        throw new AssertionError("block must be either a header block or a primitive block.");
    }

    Fileformat.Blob.Builder blobBuilder = Fileformat.Blob.newBuilder();
    byte[] serializedBlock = block.toByteArray();
    byte[] deflatedBlock = new byte[serializedBlock.length];
    int deflatedSize = deflate(serializedBlock, deflatedBlock);
    if (deflatedSize < 0) {
        LOG.debug("Deflate did not reduce the size of a block. Saving it uncompressed.");
        blobBuilder.setRaw(ByteString.copyFrom(serializedBlock));
    } else {
        blobBuilder.setZlibData(ByteString.copyFrom(deflatedBlock, 0, deflatedSize));
        blobBuilder.setRawSize(serializedBlock.length);
    }
    byte[] serializedBlob = blobBuilder.build().toByteArray();

    Fileformat.BlobHeader blobHeader = Fileformat.BlobHeader.newBuilder()
            .setType(blobTypeString).setDatasize(serializedBlob.length).build();
    byte[] serializedBlobHeader = blobHeader.toByteArray();
    try {
        // "Returns a big-endian representation of value in a 4-element byte array"
        downstream.write(Ints.toByteArray(serializedBlobHeader.length));
        downstream.write(serializedBlobHeader);
        downstream.write(serializedBlob);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:41,代码来源:PBFOutput.java


示例19: writeEnd

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void writeEnd() throws IOException {
    // Finish any partially-completed block.
    endBlock();
    // Send a primitive block with no primitive group to the writer thread, signaling it to shut down and clean up.
    try {
        synchronousQueue.put(Osmformat.PrimitiveBlock.getDefaultInstance());
        writerThread.join();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Finished writing PBF format.");
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:14,代码来源:PBFOutput.java


示例20: writeRelation

import org.openstreetmap.osmosis.osmbinary.Osmformat; //导入依赖的package包/类
@Override
public void writeRelation(long id, Relation relation) throws IOException {

    checkBlockTransition(OSMEntity.Type.RELATION);
    Osmformat.Relation.Builder builder = Osmformat.Relation.newBuilder().setId(id);

    /* Tags */
    if (relation.tags != null) {
        for (OSMEntity.Tag tag : relation.tags) {
            if (tag.value == null) tag.value = "";
            builder.addKeys(stringTable.getCode(tag.key));
            builder.addVals(stringTable.getCode(tag.value));
        }
    }

    /* Relation members */
    long lastMemberId = 0;
    for (Relation.Member member : relation.members) {
        builder.addMemids(member.id - lastMemberId); // delta-coded member references
        lastMemberId = member.id;
        builder.addRolesSid(stringTable.getCode(member.role));
        Osmformat.Relation.MemberType memberType;
        if (member.type == OSMEntity.Type.NODE) {
            memberType = Osmformat.Relation.MemberType.NODE;
        } else if (member.type == OSMEntity.Type.WAY) {
            memberType = Osmformat.Relation.MemberType.WAY;
        } else if (member.type == OSMEntity.Type.RELATION) {
            memberType = Osmformat.Relation.MemberType.RELATION;
        } else {
            throw new RuntimeException("Member type was not defined.");
        }
        builder.addTypes(memberType);
    }

    /* TODO Should we trigger the build here or just call with the builder? */
    primitiveGroupBuilder.addRelations(builder.build());

}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:39,代码来源:PBFOutput.java



注:本文中的org.openstreetmap.osmosis.osmbinary.Osmformat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ODataApplicationException类代码示例发布时间:2022-05-23
下一篇:
Java StatsSnapshot类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap