当前位置: 首页 > 知识库问答 >
问题:

java库“CityGML4J”出错

严瀚昂
2023-03-14

我是一个新程序员,我想编写java程序,并使用CityGML4j库。我看到了citygml4j程序的一些示例,但当我在netbeans中运行它们时,我看到以下错误:

线程“main”java.lang.NoClassDeffounder中出现异常错误:com/sun/xml/stream/writers/xmlwriter(位于org.citygml4j.builder.jaxb.xml.io.writer.jaxboutputfactor.createcitygmlwriter(未知源)(位于org.citygml4j.builder.jaxb.xml.io.writer.jaxboutputfactor.createcitygmlwriter(未知源)(位于

Java程序:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package buildingcreator;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.citygml4j.CityGMLContext;
import org.citygml4j.builder.CityGMLBuilder;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.CityGMLClass;
import org.citygml4j.model.citygml.building.AbstractBoundarySurface;
import org.citygml4j.model.citygml.building.BoundarySurfaceProperty;
import org.citygml4j.model.citygml.building.Building;
import org.citygml4j.model.citygml.building.GroundSurface;
import org.citygml4j.model.citygml.building.RoofSurface;
import org.citygml4j.model.citygml.building.WallSurface;
import org.citygml4j.model.citygml.core.CityModel;
import org.citygml4j.model.citygml.core.CityObjectMember;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.gml.geometry.complexes.CompositeSurface;
import org.citygml4j.model.gml.geometry.primitives.Polygon;
import org.citygml4j.model.gml.geometry.primitives.Solid;
import org.citygml4j.model.gml.geometry.primitives.SolidProperty;
import org.citygml4j.model.gml.geometry.primitives.SurfaceProperty;
import org.citygml4j.model.module.citygml.CityGMLVersion;
import org.citygml4j.util.gmlid.DefaultGMLIdManager;
import org.citygml4j.util.gmlid.GMLIdManager;
import org.citygml4j.xml.io.CityGMLOutputFactory;
import org.citygml4j.xml.io.writer.CityGMLWriter;

/**
 *
 * @author Simin
 */
public class BuildingCreator {
    public static void main(String[] args) throws Exception {
        new BuildingCreator().doMain();
    }

    public void doMain() throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

        System.out.println(df.format(new Date()) + "setting up citygml4j context and JAXB builder");
        CityGMLContext ctx = new CityGMLContext();
        CityGMLBuilder builder = ctx.createCityGMLBuilder();

        System.out.println(df.format(new Date()) + "creating LOD2 building as citygml4j in-memory object tree");
        GMLGeometryFactory geom = new GMLGeometryFactory();

        GMLIdManager gmlIdManager = DefaultGMLIdManager.getInstance();

        Building building = new Building();

        Polygon ground = geom.createLinearPolygon(new double[] {0,0,0, 0,12,0, 6,12,0, 6,0,0, 0,0,0}, 3);
        Polygon wall_1 = geom.createLinearPolygon(new double[] {6,0,0, 6,12,0, 6,12,6, 6,0,6, 6,0,0}, 3);
        Polygon wall_2 = geom.createLinearPolygon(new double[] {0,0,0, 0,0,6, 0,12,6, 0,12,0, 0,0,0}, 3);
        Polygon wall_3 = geom.createLinearPolygon(new double[] {0,0,0, 6,0,0, 6,0,6, 3,0,9, 0,0,6, 0,0,0}, 3);
        Polygon wall_4 = geom.createLinearPolygon(new double[] {6,12,0, 0,12,0, 0,12,6, 3,12,9, 6,12,6, 6,12,0}, 3);
        Polygon roof_1 = geom.createLinearPolygon(new double[] {6,0,6, 6,12,6, 3,12,9, 3,0,9, 6,0,6}, 3);
        Polygon roof_2 = geom.createLinearPolygon(new double[] {0,0,6, 3,0,9, 3,12,9, 0,12,6, 0,0,6}, 3);

        ground.setId(gmlIdManager.generateUUID());
        wall_1.setId(gmlIdManager.generateUUID());
        wall_2.setId(gmlIdManager.generateUUID());
        wall_3.setId(gmlIdManager.generateUUID());
        wall_4.setId(gmlIdManager.generateUUID());
        roof_1.setId(gmlIdManager.generateUUID());
        roof_2.setId(gmlIdManager.generateUUID());

        // lod2 solid
        List<SurfaceProperty> surfaceMember = new ArrayList<SurfaceProperty>();
        surfaceMember.add(new SurfaceProperty('#' + ground.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_1.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_2.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_3.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_4.getId()));
        surfaceMember.add(new SurfaceProperty('#' + roof_1.getId()));
        surfaceMember.add(new SurfaceProperty('#' + roof_2.getId()));

        CompositeSurface compositeSurface = new CompositeSurface();
        compositeSurface.setSurfaceMember(surfaceMember);       
        Solid solid = new Solid();
        solid.setExterior(new SurfaceProperty(compositeSurface));

        building.setLod2Solid(new SolidProperty(solid));

        // thematic boundary surfaces
        List<BoundarySurfaceProperty> boundedBy = new ArrayList<BoundarySurfaceProperty>();
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_GROUND_SURFACE, ground));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_1));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_2));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_3));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_4));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_ROOF_SURFACE, roof_1));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_ROOF_SURFACE, roof_2));       
        building.setBoundedBySurface(boundedBy);

        CityModel cityModel = new CityModel();
        cityModel.setBoundedBy(building.calcBoundedBy(false));
        cityModel.addCityObjectMember(new CityObjectMember(building));

        System.out.println(df.format(new Date()) + "writing citygml4j object tree");
        CityGMLOutputFactory out = builder.createCityGMLOutputFactory(CityGMLVersion.DEFAULT);
            CityGMLWriter writer = out.createCityGMLWriter(new File("LOD2_Building_v200.gml"));
        writer.setPrefixes(CityGMLVersion.DEFAULT);
        writer.setSchemaLocations(CityGMLVersion.DEFAULT);
        writer.setIndentString("  ");
        writer.write(cityModel);    
                writer.close(); 

        System.out.println(df.format(new Date()) + "CityGML file LOD2_Building_v200.gml written");
        System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
    }

    private BoundarySurfaceProperty createBoundarySurface(CityGMLClass type, Polygon geometry) {
        AbstractBoundarySurface boundarySurface = null;

        switch (type) {
        case BUILDING_WALL_SURFACE:
            boundarySurface = new WallSurface();
            break;
        case BUILDING_ROOF_SURFACE:
            boundarySurface = new RoofSurface();
            break;
        case BUILDING_GROUND_SURFACE:
            boundarySurface = new GroundSurface();
            break;
        default:
            break;
        }

        if (boundarySurface != null) {
            boundarySurface.setLod2MultiSurface(new MultiSurfaceProperty(new MultiSurface(geometry)));
            return new BoundarySurfaceProperty(boundarySurface);
        }

        return null;

        }
}

共有1个答案

许沛
2023-03-14

还要将所有依赖的JAR放在类路径上。您将在citygml4j发行包的lib子文件夹中找到这些JAR。您使用的是citygml4j的哪个版本?类路径上似乎缺少sjsxp.jar。但是,sjsxp.jar在citygml4j的最新2.2版本中被替换了。

citygml4j也可以作为Maven工件使用。这使得依赖关系管理变得简单得多。

<dependency>
  <groupId>org.citygml4j</groupId>
  <artifactId>citygml4j</artifactId>
  <version>2.2</version>
</dependency>
 类似资料:
  • 有人能帮帮我吗?在网上找不到有关此问题的任何内容。

  • 我正在尝试为协议缓冲区构建Java运行时库。我在Windows和OS X上都犯了错误,因为我遵循了Protocol Buffers项目(从中克隆而来)中Java目录下的自述指令https://github.com/google/protobuf). 当我在protobuf/java目录下运行

  • 问题内容: 我正在编写一种算法,它将通过Java中所有可用的Mongo数据库。 在Windows Shell上,我只是做 如何在Java中执行此操作并获取所有可用数据库的列表? 问题答案: 您将这样做: 这只会为您提供所有可用数据库名称的列表。 您可以在此处查看文档。 更新: 就像下面提到的@CydrickT一样,它已被弃用,因此我们需要切换到:

  • 如果有人能在这里帮忙,我真的很高兴。

  • 我试图使用Java执行此查询 但是在[括号]上出现了一个错误 线程“main”net.ucanaccess.jdbc.ucanaccessSQLException:UCAEXC:::4.0.4意外标记:]在net.ucanaccess.jdbc.ucanaccessStatement.executeQuery(ucanaccessStatement.java:218)在main.main(main

  • 我正在尝试删除从数据库中单击的某些行。每一行都显示出来,并有一个删除按钮来删除某一行。Onclick我从行中获取ID,所有这些都起作用了。就在我查看网络时,它返回一个500的错误。这是我的密码 使用findCountrys方法 删除DAO