GML2BasicParser issue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GML2BasicParser issue

Xavier Thomas
I am using the GM2BasicParser with the following code:

---------------------------------------
        File out = new File("out.gml");
        GML2BasicParser parser = new GML2BasicParser();
        FeatureCollection features = parser.parseSimpleFeatureCollection(out);
---------------------------------------

(The out.gml file is given below in this post)

Then I get the following Exception in parser.parseSimpleFeatureCollection(out):
---------------------------------------
        java.lang.ClassCastException: org.geotools.feature.simple.SimpleFeatureImpl cannot be cast to java.util.ArrayList at org.n52.wps.io.datahandler.parser.GML2BasicParser.parseSimpleFeatureCollection(GML2BasicParser.java:183) ~[52n-wps-io-geotools-3.3.2-SNAPSHOT.jar:na]
---------------------------------------

Indeed, in GML2BasicParser.java, line 182, there is the following cast operation:
        List<?> possibleSimpleFeatureList = ((ArrayList<?>) ((HashMap<?, ?>) parsedData).get("featureMember"));
The parsed data has type HashMap and not HashMap<?, ?>. I’m not getting used of this notation ‘HashMap<?, ?>’, but I suppose it’s here for generic purpose.

When I try to evaluate the expression ((HashMap)parsedData).get(‘featureMember’), the result has the SimpleFeatureImpl type with a content as expected (POLYGON geometry…)

The out.gml is an output of gdal_polygonize.py.
Notice also that out.gml can be opened in QGIS
I am asking if it is a GML version issue… ?

out.gml
---------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ogr.maptools.org/ out.xsd"
     xmlns:ogr="http://ogr.maptools.org/"
     xmlns:gml="http://www.opengis.net/gml">
  <gml:boundedBy>
    <gml:Box>
      <gml:coord><gml:X>440294.0190912703</gml:X><gml:Y>4636802.446916306</gml:Y></gml:coord>
      <gml:coord><gml:X>444524.0190912703</gml:X><gml:Y>4641602.446916306</gml:Y></gml:coord>
    </gml:Box>
  </gml:boundedBy>
                                                                                               
  <gml:featureMember>
    <ogr:out fid="out.0">
      <ogr:geometryProperty><gml:Polygon srsName="EPSG:26912"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>442724.019091270340141,4641602.446916306391358 442724.019091270340141,4641572.446916306391358 442694.019091270340141,4641572.446916306391358 442574.019091270340141,4641572.446916306391358 442574.019091270340141,4641542.446916306391358 442544.019091270340141,4641542.446916306391358 442454.019091270340141,4641542.446916306391358 442454.019091270340141,4641512.446916306391358 442424.019091270340141,4641512.446916306391358 442364.019091270340141,4641512.446916306391358 442364.019091270340141,4641482.446916306391358 442334.019091270340141,4641482.446916306391358 442304.019091270340141,4641482.446916306391358 442304.019091270340141,4641452.446916306391358 442274.019091270340141,4641452.446916306391358 442244.019091270340141,4641452.446916306391358 442244.019091270340141,4641392.446916306391358 442214.019091270340141,4641392.446916306391358 442214.019091270340141,4641332.446916306391358 442184.019091270340141,4641332.446916306391358 442184.019091270340141,4641272.446916306391358 442154.019091270340141,4641272.446916306391358 442154.019091270340141,4641242.446916306391358 442124.019091270340141,4641242.446916306391358 442124.019091270340141,4641212.446916306391358 442094.019091270340141,4641212.446916306391358 442094.019091270340141,4641152.446916306391358 442064.019091270340141,4641152.446916306391358 442064.019091270340141,4641122.446916306391358 442034.019091270340141,4641122.446916306391358 442034.019091270340141,4641062.446916306391358 442004.019091270340141,4641062.446916306391358 442004.019091270340141,4641002.446916306391358 441974.019091270340141,4641002.446916306391358 441974.019091270340141,4640972.446916306391358 441944.019091270340141,4640972.446916306391358 441944.019091270340141,4640912.446916306391358 441914.019091270340141,4640912.446916306391358 441914.019091270340141,4640852.446916306391358 441884.019091270340141,4640852.446916306391358 441884.019091270340141,4640522.446916306391358 441854.019091270340141,4640522.446916306391358 441854.019091270340141,4640432.446916306391358 441824.019091270340141,4640432.446916306391358 441824.019091270340141,4640162.446916306391358 441794.019091270340141,4640162.446916306391358 441794.019091270340141,4640042.446916306391358 441764.019091270340141,4640042.446916306391358 441764.019091270340141,4639922.446916306391358 441734.019091270340141,4639922.446916306391358 441644.019091270340141,4639922.446916306391358 441644.019091270340141,4639892.446916306391358 441614.019091270340141,4639892.446916306391358 441554.019091270340141,4639892.446916306391358 441554.019091270340141,4639862.446916306391358 441524.019091270340141,4639862.446916306391358 441524.019091270340141,4639832.446916306391358 441494.019091270340141,4639832.446916306391358 441434.019091270340141,4639832.446916306391358 441434.019091270340141,4639802.446916306391358 441014.019091270340141,4639802.446916306391358 441014.019091270340141,4639832.446916306391358 440864.019091270340141,4639832.446916306391358 440864.019091270340141,4639802.446916306391358 440834.019091270340141,4639802.446916306391358 440834.019091270340141,4639742.446916306391358 440804.019091270340141,4639742.446916306391358 440804.019091270340141,4639682.446916306391358 440774.019091270340141,4639682.446916306391358 440774.019091270340141,4639592.446916306391358 440744.019091270340141,4639592.446916306391358 440744.019091270340141,4639532.446916306391358 440714.019091270340141,4639532.446916306391358 440714.019091270340141,4639502.446916306391358 440684.019091270340141,4639502.446916306391358 440684.019091270340141,4639472.446916306391358 440654.019091270340141,4639472.446916306391358 440624.019091270340141,4639472.446916306391358 440624.019091270340141,4639412.446916306391358 440594.019091270340141,4639412.446916306391358 440594.019091270340141,4639382.446916306391358 440564.019091270340141,4639382.446916306391358 440534.019091270340141,4639382.446916306391358 440534.019091270340141,4639322.446916306391358 440504.019091270340141,4639322.446916306391358 440504.019091270340141,4639292.446916306391358 440474.019091270340141,4639292.446916306391358 440474.019091270340141,4639262.446916306391358 440444.019091270340141,4639262.446916306391358 440444.019091270340141,4639232.446916306391358 440414.019091270340141,4639232.446916306391358 440414.019091270340141,4639112.446916306391358 440384.019091270340141,4639112.446916306391358 440384.019091270340141,4639022.446916306391358 440354.019091270340141,4639022.446916306391358 440354.019091270340141,4638992.446916306391358 440324.019091270340141,4638992.446916306391358 440324.019091270340141,4638932.446916306391358 440294.019091270340141,4638932.446916306391358 440294.019091270340141,4638872.446916306391358 440324.019091270340141,4638872.446916306391358 440324.019091270340141,4638812.446916306391358 440354.019091270340141,4638812.446916306391358 440354.019091270340141,4638752.446916306391358 440384.019091270340141,4638752.446916306391358 440384.019091270340141,4638722.446916306391358 440414.019091270340141,4638722.446916306391358 440414.019091270340141,4638662.446916306391358 440444.019091270340141,4638662.446916306391358 440444.019091270340141,4638632.446916306391358 440474.019091270340141,4638632.446916306391358 440474.019091270340141,4638602.446916306391358 440504.019091270340141,4638602.446916306391358 440504.019091270340141,4638572.446916306391358 440534.019091270340141,4638572.446916306391358 440534.019091270340141,4638512.446916306391358 440564.019091270340141,4638512.446916306391358 440564.019091270340141,4638482.446916306391358 440654.019091270340141,4638482.446916306391358 440654.019091270340141,4638452.446916306391358 440714.019091270340141,4638452.446916306391358 440714.019091270340141,4638422.446916306391358 440744.019091270340141,4638422.446916306391358 440744.019091270340141,4638392.446916306391358 440864.019091270340141,4638392.446916306391358 440864.019091270340141,4638362.446916306391358 440894.019091270340141,4638362.446916306391358 440894.019091270340141,4638332.446916306391358 440924.019091270340141,4638332.446916306391358 440924.019091270340141,4638302.446916306391358 440954.019091270340141,4638302.446916306391358 440954.019091270340141,4638272.446916306391358 440984.019091270340141,4638272.446916306391358 440984.019091270340141,4638242.446916306391358 441014.019091270340141,4638242.446916306391358 441014.019091270340141,4638212.446916306391358 441044.019091270340141,4638212.446916306391358 441044.019091270340141,4638182.446916306391358 441074.019091270340141,4638182.446916306391358 441074.019091270340141,4638152.446916306391358 441104.019091270340141,4638152.446916306391358 441104.019091270340141,4638122.446916306391358 441164.019091270340141,4638122.446916306391358 441164.019091270340141,4638092.446916306391358 441194.019091270340141,4638092.446916306391358 441194.019091270340141,4638062.446916306391358 441224.019091270340141,4638062.446916306391358 441224.019091270340141,4638032.446916306391358 441254.019091270340141,4638032.446916306391358 441254.019091270340141,4638002.446916306391358 441284.019091270340141,4638002.446916306391358 441284.019091270340141,4637972.446916306391358 441254.019091270340141,4637972.446916306391358 441254.019091270340141,4637882.446916306391358 441224.019091270340141,4637882.446916306391358 441224.019091270340141,4637612.446916306391358 441254.019091270340141,4637612.446916306391358 441254.019091270340141,4637552.446916306391358 441284.019091270340141,4637552.446916306391358 441284.019091270340141,4637522.446916306391358 441314.019091270340141,4637522.446916306391358 441314.019091270340141,4637492.446916306391358 441344.019091270340141,4637492.446916306391358 441344.019091270340141,4637282.446916306391358 441374.019091270340141,4637282.446916306391358 441374.019091270340141,4637252.446916306391358 441464.019091270340141,4637252.446916306391358 441464.019091270340141,4637222.446916306391358 441524.019091270340141,4637222.446916306391358 441524.019091270340141,4637192.446916306391358 441614.019091270340141,4637192.446916306391358 441614.019091270340141,4637162.446916306391358 441644.019091270340141,4637162.446916306391358 441644.019091270340141,4637132.446916306391358 441884.019091270340141,4637132.446916306391358 441884.019091270340141,4637162.446916306391358 442184.019091270340141,4637162.446916306391358 442214.019091270340141,4637162.446916306391358 442214.019091270340141,4637192.446916306391358 442244.019091270340141,4637192.446916306391358 442274.019091270340141,4637192.446916306391358 442274.019091270340141,4637222.446916306391358 442304.019091270340141,4637222.446916306391358 442334.019091270340141,4637222.446916306391358 442334.019091270340141,4637252.446916306391358 442394.019091270340141,4637252.446916306391358 442424.019091270340141,4637252.446916306391358 442424.019091270340141,4637282.446916306391358 442454.019091270340141,4637282.446916306391358 442484.019091270340141,4637282.446916306391358 442484.019091270340141,4637312.446916306391358 442514.019091270340141,4637312.446916306391358 442544.019091270340141,4637312.446916306391358 442544.019091270340141,4637342.446916306391358 442634.019091270340141,4637342.446916306391358 442664.019091270340141,4637342.446916306391358 442664.019091270340141,4637372.446916306391358 442724.019091270340141,4637372.446916306391358 442754.019091270340141,4637372.446916306391358 442754.019091270340141,4637402.446916306391358 442784.019091270340141,4637402.446916306391358 442784.019091270340141,4637492.446916306391358 442814.019091270340141,4637492.446916306391358 442814.019091270340141,4637462.446916306391358 442874.019091270340141,4637462.446916306391358 442874.019091270340141,4637432.446916306391358 442904.019091270340141,4637432.446916306391358 442904.019091270340141,4637402.446916306391358 442964.019091270340141,4637402.446916306391358 442964.019091270340141,4637372.446916306391358 442994.019091270340141,4637372.446916306391358 442994.019091270340141,4637342.446916306391358 443024.019091270340141,4637342.446916306391358 443024.019091270340141,4637312.446916306391358 443054.019091270340141,4637312.446916306391358 443054.019091270340141,4637282.446916306391358 443084.019091270340141,4637282.446916306391358 443084.019091270340141,4637192.446916306391358 443114.019091270340141,4637192.446916306391358 443114.019091270340141,4637102.446916306391358 443144.019091270340141,4637102.446916306391358 443144.019091270340141,4637072.446916306391358 443174.019091270340141,4637072.446916306391358 443174.019091270340141,4637042.446916306391358 443204.019091270340141,4637042.446916306391358 443204.019091270340141,4637012.446916306391358 443234.019091270340141,4637012.446916306391358 443234.019091270340141,4636982.446916306391358 443264.019091270340141,4636982.446916306391358 443264.019091270340141,4636952.446916306391358 443324.019091270340141,4636952.446916306391358 443324.019091270340141,4636922.446916306391358 443354.019091270340141,4636922.446916306391358 443354.019091270340141,4636892.446916306391358 443414.019091270340141,4636892.446916306391358 443414.019091270340141,4636862.446916306391358 443444.019091270340141,4636862.446916306391358 443444.019091270340141,4636832.446916306391358 443474.019091270340141,4636832.446916306391358 443474.019091270340141,4636802.446916306391358 443504.019091270340141,4636802.446916306391358 443504.019091270340141,4636862.446916306391358 443534.019091270340141,4636862.446916306391358 443534.019091270340141,4636922.446916306391358 443564.019091270340141,4636922.446916306391358 443564.019091270340141,4636952.446916306391358 443594.019091270340141,4636952.446916306391358 443594.019091270340141,4637012.446916306391358 443624.019091270340141,4637012.446916306391358 443624.019091270340141,4637072.446916306391358 443654.019091270340141,4637072.446916306391358 443654.019091270340141,4637132.446916306391358 443684.019091270340141,4637132.446916306391358 443684.019091270340141,4637162.446916306391358 443714.019091270340141,4637162.446916306391358 443714.019091270340141,4637192.446916306391358 443744.019091270340141,4637192.446916306391358 443744.019091270340141,4637222.446916306391358 443774.019091270340141,4637222.446916306391358 443774.019091270340141,4637252.446916306391358 443804.019091270340141,4637252.446916306391358 443804.019091270340141,4637282.446916306391358 443834.019091270340141,4637282.446916306391358 443834.019091270340141,4637342.446916306391358 443864.019091270340141,4637342.446916306391358 443864.019091270340141,4637432.446916306391358 443894.019091270340141,4637432.446916306391358 443894.019091270340141,4637492.446916306391358 443924.019091270340141,4637492.446916306391358 443924.019091270340141,4637522.446916306391358 443954.019091270340141,4637522.446916306391358 443954.019091270340141,4637582.446916306391358 443984.019091270340141,4637582.446916306391358 443984.019091270340141,4637612.446916306391358 444014.019091270340141,4637612.446916306391358 444014.019091270340141,4637642.446916306391358 444044.019091270340141,4637642.446916306391358 444044.019091270340141,4637672.446916306391358 444074.019091270340141,4637672.446916306391358 444074.019091270340141,4637792.446916306391358 444104.019091270340141,4637792.446916306391358 444104.019091270340141,4637882.446916306391358 444134.019091270340141,4637882.446916306391358 444134.019091270340141,4637942.446916306391358 444164.019091270340141,4637942.446916306391358 444164.019091270340141,4637972.446916306391358 444194.019091270340141,4637972.446916306391358 444194.019091270340141,4638002.446916306391358 444224.019091270340141,4638002.446916306391358 444224.019091270340141,4638032.446916306391358 444254.019091270340141,4638032.446916306391358 444254.019091270340141,4638062.446916306391358 444284.019091270340141,4638062.446916306391358 444284.019091270340141,4638092.446916306391358 444314.019091270340141,4638092.446916306391358 444314.019091270340141,4638122.446916306391358 444344.019091270340141,4638122.446916306391358 444344.019091270340141,4638152.446916306391358 444374.019091270340141,4638152.446916306391358 444374.019091270340141,4638182.446916306391358 444404.019091270340141,4638182.446916306391358 444404.019091270340141,4638212.446916306391358 444434.019091270340141,4638212.446916306391358 444434.019091270340141,4638242.446916306391358 444464.019091270340141,4638242.446916306391358 444464.019091270340141,4638272.446916306391358 444494.019091270340141,4638272.446916306391358 444494.019091270340141,4638332.446916306391358 444524.019091270340141,4638332.446916306391358 444524.019091270340141,4638422.446916306391358 444494.019091270340141,4638422.446916306391358 444494.019091270340141,4638602.446916306391358 444464.019091270340141,4638602.446916306391358 444464.019091270340141,4638662.446916306391358 444434.019091270340141,4638662.446916306391358 444434.019091270340141,4638722.446916306391358 444404.019091270340141,4638722.446916306391358 444404.019091270340141,4638962.446916306391358 444434.019091270340141,4638962.446916306391358 444434.019091270340141,4639022.446916306391358 444404.019091270340141,4639022.446916306391358 444404.019091270340141,4639052.446916306391358 444374.019091270340141,4639052.446916306391358 444374.019091270340141,4639082.446916306391358 444344.019091270340141,4639082.446916306391358 444344.019091270340141,4639142.446916306391358 444314.019091270340141,4639142.446916306391358 444314.019091270340141,4639232.446916306391358 444284.019091270340141,4639232.446916306391358 444284.019091270340141,4639472.446916306391358 444254.019091270340141,4639472.446916306391358 444254.019091270340141,4639562.446916306391358 444224.019091270340141,4639562.446916306391358 444224.019091270340141,4639592.446916306391358 444194.019091270340141,4639592.446916306391358 444194.019091270340141,4639652.446916306391358 444164.019091270340141,4639652.446916306391358 444164.019091270340141,4639742.446916306391358 444134.019091270340141,4639742.446916306391358 444134.019091270340141,4639802.446916306391358 444104.019091270340141,4639802.446916306391358 444104.019091270340141,4639922.446916306391358 444074.019091270340141,4639922.446916306391358 444074.019091270340141,4639982.446916306391358 444044.019091270340141,4639982.446916306391358 444044.019091270340141,4640012.446916306391358 444014.019091270340141,4640012.446916306391358 444014.019091270340141,4640042.446916306391358 443984.019091270340141,4640042.446916306391358 443984.019091270340141,4640162.446916306391358 444014.019091270340141,4640162.446916306391358 444014.019091270340141,4640252.446916306391358 444044.019091270340141,4640252.446916306391358 444044.019091270340141,4640282.446916306391358 444074.019091270340141,4640282.446916306391358 444074.019091270340141,4640312.446916306391358 444104.019091270340141,4640312.446916306391358 444104.019091270340141,4640462.446916306391358 444044.019091270340141,4640462.446916306391358 444044.019091270340141,4640492.446916306391358 443984.019091270340141,4640492.446916306391358 443984.019091270340141,4640522.446916306391358 443954.019091270340141,4640522.446916306391358 443954.019091270340141,4640642.446916306391358 443924.019091270340141,4640642.446916306391358 443924.019091270340141,4640912.446916306391358 443954.019091270340141,4640912.446916306391358 443954.019091270340141,4640942.446916306391358 443864.019091270340141,4640942.446916306391358 443864.019091270340141,4640972.446916306391358 443804.019091270340141,4640972.446916306391358 443804.019091270340141,4641002.446916306391358 443654.019091270340141,4641002.446916306391358 443654.019091270340141,4641032.446916306391358 443594.019091270340141,4641032.446916306391358 443594.019091270340141,4641062.446916306391358 443534.019091270340141,4641062.446916306391358 443534.019091270340141,4641092.446916306391358 443474.019091270340141,4641092.446916306391358 443474.019091270340141,4641152.446916306391358 443444.019091270340141,4641152.446916306391358 443444.019091270340141,4641182.446916306391358 443414.019091270340141,4641182.446916306391358 443414.019091270340141,4641212.446916306391358 443384.019091270340141,4641212.446916306391358 443384.019091270340141,4641272.446916306391358 443354.019091270340141,4641272.446916306391358 443354.019091270340141,4641302.446916306391358 443264.019091270340141,4641302.446916306391358 443264.019091270340141,4641332.446916306391358 443234.019091270340141,4641332.446916306391358 443234.019091270340141,4641362.446916306391358 443174.019091270340141,4641362.446916306391358 443174.019091270340141,4641392.446916306391358 443144.019091270340141,4641392.446916306391358 443144.019091270340141,4641422.446916306391358 443114.019091270340141,4641422.446916306391358 443114.019091270340141,4641452.446916306391358 443084.019091270340141,4641452.446916306391358 443084.019091270340141,4641482.446916306391358 443054.019091270340141,4641482.446916306391358 443054.019091270340141,4641512.446916306391358 443024.019091270340141,4641512.446916306391358 443024.019091270340141,4641542.446916306391358 442994.019091270340141,4641542.446916306391358 442994.019091270340141,4641512.446916306391358 442844.019091270340141,4641512.446916306391358 442844.019091270340141,4641542.446916306391358 442784.019091270340141,4641542.446916306391358 442784.019091270340141,4641572.446916306391358 442754.019091270340141,4641572.446916306391358 442754.019091270340141,4641602.446916306391358 442724.019091270340141,4641602.446916306391358</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
      <ogr:DN>1</ogr:DN>
    </ogr:out>
  </gml:featureMember>
</ogr:FeatureCollection>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GML2BasicParser issue

BenjaminPross
The issue seems to be that there is only one feature in the collection. There need to be an additional check for single features in the code. Are you using the development version?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GML2BasicParser issue

Xavier Thomas
Hi Benjamin, Yes, this is the dev version. Indeed it appears that the featureMember can be a SimpleFeature, not necessarily a list. FYI, I quickly and recently fix it using the following code: public SimpleFeatureCollection parseSimpleFeatureCollection(File file) { QName schematypeTuple = determineFeatureTypeSchema(file); Configuration configuration = null; boolean shouldSetParserStrict = true; String schemaLocation = schematypeTuple.getLocalPart(); if (schemaLocation != null && schematypeTuple.getNamespaceURI() != null) { SchemaRepository.registerSchemaLocation( schematypeTuple.getNamespaceURI(), schemaLocation); configuration = new ApplicationSchemaConfiguration( schematypeTuple.getNamespaceURI(), schemaLocation); } else { configuration = new GMLConfiguration(); shouldSetParserStrict = false; } org.geotools.xml.Parser parser = new org.geotools.xml.Parser( configuration); // parse SimpleFeatureCollection fc = DefaultFeatureCollections.newCollection(); try { Object parsedData = null; try { parser.setStrict(shouldSetParserStrict); parsedData = parser.parse(new FileInputStream(file)); } catch (SAXException e5) { // assume the xsd containing the schema was not found configuration = new GMLConfiguration(); parser = new org.geotools.xml.Parser(configuration); parser.setStrict(false); parsedData = parser.parse(new FileInputStream(file)); } if (parsedData instanceof SimpleFeatureCollection) { fc = (SimpleFeatureCollection) parsedData; } else if (parsedData instanceof HashMap) { if (((HashMap) parsedData).get("featureMember") instanceof SimpleFeature) { SimpleFeature sf = (SimpleFeature)((HashMap) parsedData).get("featureMember"); List simpleFeatureList = new ArrayList(); SimpleFeatureType sft = sf.getType(); simpleFeatureList.add(sf); fc = new ListFeatureCollection(sft, simpleFeatureList); } else { List possibleSimpleFeatureList = ((ArrayList) ((HashMap) parsedData) .get("featureMember")); if (possibleSimpleFeatureList != null) { List simpleFeatureList = new ArrayList(); SimpleFeatureType sft = null; for (Object possibleSimpleFeature : possibleSimpleFeatureList) { if (possibleSimpleFeature instanceof SimpleFeature) { SimpleFeature sf = ((SimpleFeature) possibleSimpleFeature); if (sft == null) { sft = sf.getType(); } simpleFeatureList.add(sf); } } fc = new ListFeatureCollection(sft, simpleFeatureList); } else { fc = (SimpleFeatureCollection) ((HashMap) parsedData) .get("FeatureCollection"); } } } SimpleFeatureIterator featureIterator = fc.features(); while (featureIterator.hasNext()) { SimpleFeature feature = (SimpleFeature) featureIterator.next(); if (feature.getDefaultGeometry() == null) { Collection properties = feature .getProperties(); for (org.opengis.feature.Property property : properties) { try { Geometry g = (Geometry) property.getValue(); if (g != null) { GeometryAttribute oldGeometryDescriptor = feature .getDefaultGeometryProperty(); GeometryType type = new GeometryTypeImpl( property.getName(), (Class) oldGeometryDescriptor .getType().getBinding(), oldGeometryDescriptor.getType() .getCoordinateReferenceSystem(), oldGeometryDescriptor.getType() .isIdentified(), oldGeometryDescriptor.getType() .isAbstract(), oldGeometryDescriptor.getType() .getRestrictions(), oldGeometryDescriptor.getType() .getSuper(), oldGeometryDescriptor.getType() .getDescription()); GeometryDescriptor newGeometryDescriptor = new GeometryDescriptorImpl( type, property.getName(), 0, 1, true, null); Identifier identifier = new GmlObjectIdImpl( feature.getID()); GeometryAttributeImpl geo = new GeometryAttributeImpl( (Object) g, newGeometryDescriptor, identifier); feature.setDefaultGeometryProperty(geo); feature.setDefaultGeometry(g); } } catch (ClassCastException e) { // do nothing } } } } return fc; } catch (Exception e) { LOGGER.error( "Exception while trying to parse GML2 FeatureCollection.", e); throw new RuntimeException(e); } }
Loading...