1

I have trouble understanding the use of the function ReprojectingFeatureCollection. Here is my code:

try {

    Double buffer = 500.0;
    String attributeBuffer = "";

    ReprojectingFeatureCollection clip_repojected = new ReprojectingFeatureCollection(clip, CRS.decode("EPSG:3857"));

    myBufferM buffered = new myBufferM();
    SimpleFeatureCollection bufferedFeatures = buffered.createBufferM(clip_repojected.collection(), buffer, attributeBuffer);

} catch (OperationNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (FactoryRegistryException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (NoSuchAuthorityCodeException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (SchemaException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (FactoryException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

So my function gets a SimpleFeatureCollection as parameter and now tries to Reproject it to EPSG:3857. I have modified the gs:BufferFeatureCollection from the list of WPS processes of GeoServer and now call it myBufferM. I am trying to Buffer a FeatureCollection in meter instead of degrees (data's default unit). Previously I had the transformation to meter build into my Class myBufferM which worked good (transforming every feature geometry itself and then buffering it and reverse transforming it).

Now I am trying to transform the geometries beforehand using the Buffer function as it was before I modified it.

The question is: am I using the ReprojectingFeatureCollection correctly? Because the results I get now are wrong (in degrees).

If you need more code I will update my question. I have reduced it to the important parts. The total code would be kind of huge.

0

Your code as provided doesn't actually compile. I have no method collection in ReprojectingFeatureCollection. But using rfc.subCollection(Filter.INCLUDE).features() to create the iterator also works for me.

Here is how I would do this:

  public static void main(String[] args) throws IOException, NoSuchAuthorityCodeException, FactoryException {
    File inFile = new File("/home/ian/Data/states/states.shp");
    DataStore inputDataStore = DataStoreFinder.getDataStore(Collections.singletonMap("url", URLs.fileToUrl(inFile)));
    int limit = 10;
    System.out.println("original");
    try (SimpleFeatureIterator itr = inputDataStore.getFeatureSource("states").getFeatures().features()) {
      int count = 0;
      while (itr.hasNext() && (count++ < limit)) {
        SimpleFeature feature = itr.next();
        System.out.println(feature.getDefaultGeometry());
      }
    }
    String inputTypeName = inputDataStore.getTypeNames()[0];
    // SimpleFeatureType inputType = inputDataStore.getSchema(inputTypeName);
    // System.out.println(inputType.getCoordinateReferenceSystem());

    FeatureSource<SimpleFeatureType, SimpleFeature> source = inputDataStore.getFeatureSource(inputTypeName);

    FeatureCollection<SimpleFeatureType, SimpleFeature> inputFeatureCollection = source.getFeatures();
    ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(inputFeatureCollection,
        CRS.decode("epsg:3857"));

    printer(rfc, limit);
  }

  /**
   * @param rfc
   */
  public static void printer(ReprojectingFeatureCollection rfc, int limit) {
    System.out.println("reprojected");
    try (SimpleFeatureIterator itr = rfc.subCollection(Filter.INCLUDE).features()) {
      int count = 0;
      while (itr.hasNext() && (count++) < limit) {
        SimpleFeature feature = itr.next();
        System.out.println(feature.getDefaultGeometry());
      }
    }
  }

which produces:

original
MULTIPOLYGON (((-88.071564 37.51099000000001, -88.087883 37.476273000000006, -88.311707 37.442852, -88.359177 37.40930899999999, -88.419853 37.420292, -88.467644 37.400757, -88.511322 37.296852, -88.501427 37.257782000000006, -88.450699 37.205669, -88.422516 37.156909999999996, -88.45047 37.098670999999996, -88.476799 37.072143999999994, -88.4907 37.06818, -88.517273 37.064769999999996, -88.559273 37.072815000000006, -88.61422 37.109047000000004, -88.68837 37.13540999999999, -88.739113 37.141182, -88.746506 37.152107, -88.863289 37.202194000000006, -88.932503 37.218407, -88.993172 37.22003599999999, -89.065033 37.185860000000005, -89.116821 37.112137000000004, -89.146347 37.093185000000005, -89.169548 37.064235999999994, -89.174332 37.025711, -89.150246 36.99844, -89.12986 36.988113, -89.193512 36.986771000000005, -89.210052 37.02897299999999, -89.237679 37.041732999999994, -89.264053 37.087124, -89.284233 37.091244, -89.303291 37.085384000000005, -89.3097 37.060908999999995, -89.264244 37.027733, -89.262001 37.008686, -89.282768 36.999207, -89.310982 37.009682, -89.38295 37.049212999999995, -89.37999 37.09908299999999, -89.423798 37.137203, -89.440521 37.165318, -89.468216 37.224266, -89.465309 37.253731, -89.489594 37.256001, -89.513885 37.276402000000004, -89.513885 37.304962, -89.50058 37.329441, -89.468742 37.339409, -89.435738 37.355717, -89.427574 37.411018, -89.453621 37.453186, -89.494781 37.491726, -89.524971 37.571957, -89.513367 37.615928999999994, -89.51918 37.650375, -89.513374 37.67984, -89.521523 37.694798000000006, -89.581436 37.706103999999996, -89.666458 37.745453, -89.675858 37.78397, -89.691055 37.804794, -89.728447 37.840992, -89.851715 37.905063999999996, -89.861046 37.905486999999994, -89.866814 37.891875999999996, -89.900551 37.875904000000006, -89.937874 37.878044, -89.978912 37.911884, -89.958229 37.963634, -90.010811 37.969318, -90.041924 37.993206, -90.119339 38.032272000000006, -90.134712 38.05395100000001, -90.207527 38.08890500000001, -90.254059 38.122169000000014, -90.289635 38.16681700000001, -90.336716 38.18871300000001, -90.364769 38.23429899999999, -90.369347 38.32355899999999, -90.358688 38.36533, -90.339607 38.39084600000001, -90.301842 38.427357, -90.265785 38.518688, -90.26123 38.532768000000004, -90.240944 38.562805, -90.183708 38.61027100000001, -90.183578 38.658772, -90.20224 38.70036300000001, -90.196571 38.72396499999999, -90.163399 38.773098000000005, -90.135178 38.785484, -90.121727 38.80051, -90.113121 38.830467, -90.132812 38.85303099999999, -90.243927 38.91450900000001, -90.278931 38.92471699999999, -90.31974 38.92490799999999, -90.413071 38.96233000000001, -90.469841 38.959179000000006, -90.530426 38.89160899999999, -90.570328 38.87132600000001, -90.627213 38.880795000000006, -90.668877 38.93525299999999, -90.70607 39.037791999999996, -90.707588 39.058178, -90.690399 39.09370000000001, -90.716736 39.14421100000001, -90.718193 39.195873000000006, -90.732338 39.22474700000001, -90.738083 39.24780999999999, -90.779343 39.29680300000001, -90.850494 39.35045199999999, -90.947891 39.40058500000001, -91.036339 39.444412, -91.064384 39.473984, -91.093613 39.52892700000001, -91.156189 39.552593, -91.203247 39.600021, -91.317665 39.68591699999999, -91.367088 39.724639999999994, -91.373421 39.76127199999999, -91.381714 39.80377200000001, -91.449188 39.86304899999999, -91.450989 39.885242000000005, -91.434052 39.90182899999999, -91.430389 39.92183700000001, -91.447243 39.94606400000001, -91.487289 40.005753, -91.504005 40.066711, -91.516129 40.134544000000005, -91.506546 40.200458999999995, -91.498932 40.25137699999999, -91.486694 40.309624000000014, -91.448593 40.371902000000006, -91.418816 40.386875, -91.385757 40.392360999999994, -91.372757 40.40298799999999, -91.385399 40.44725, -91.374794 40.50365400000001, -91.382103 40.52849599999999, -91.412872 40.54799299999999, -91.411118 40.572970999999995, -91.37561 40.60343900000001, -91.262062 40.639545, -91.214912 40.64381800000001, -91.162498 40.65631099999999, -91.129158 40.68214800000001, -91.119987 40.70540199999999, -91.092751 40.76154700000001, -91.088905 40.833729000000005, -91.04921 40.87958499999999, -90.983276 40.92392699999999, -90.960709 40.950503999999995, -90.954651 41.07036199999999, -90.957787 41.10435899999999, -90.990341 41.14437100000001, -91.018257 41.16582500000001, -91.05632 41.17625799999999, -91.101524 41.23152200000001, -91.102348 41.267818000000005, -91.07328 41.334895999999986, -91.055786 41.40137899999999, -91.027489 41.423508, -91.000694 41.431084, -90.949654 41.421234, -90.844139 41.44462200000001, -90.7799 41.449820999999986, -90.708214 41.450062, -90.658791 41.46231800000001, -90.6007 41.50958600000001, -90.54084 41.52597, -90.454994 41.527546, -90.434967 41.543578999999994, -90.423004 41.567272, -90.348366 41.586849, -90.339348 41.60279800000001, -90.341133 41.64909, -90.326027 41.722736, -90.304886 41.75646599999999, -90.25531 41.78173799999999, -90.195839 41.80613700000001, -90.154518 41.93077500000001, -90.14267 41.98396299999999, -90.150536 42.03342799999999, -90.168098 42.06104300000001, -90.166649 42.103745, -90.176086 42.12050199999999, -90.191574 42.12268800000001, -90.230934 42.15972099999999, -90.323601 42.19731899999999, -90.367729 42.21020899999999, -90.407173 42.24264500000001, -90.417984 42.263924, -90.427681 42.340633, -90.441597 42.360073, -90.491043 42.38878299999999, -90.563583 42.42183700000001, -90.605827 42.46055999999999, -90.648346 42.47564299999999, -90.651772 42.494698, -90.638329 42.50936100000001, -90.419975 42.508362000000005, -89.923569 42.504108, -89.834618 42.50345999999999, -89.400497 42.49749, -89.359444 42.497906, -88.939079 42.49086399999999, -88.764954 42.490905999999995, -88.70652 42.489655, -88.297897 42.49197000000001, -88.194702 42.48961299999999, -87.79731 42.48913200000001, -87.836945 42.314212999999995, -87.760239 42.15645599999999, -87.670547 42.059822, -87.612625 41.847331999999994, -87.529861 41.723591, -87.532646 41.46971500000001, -87.532448 41.30130399999999, -87.531731 41.173756, -87.532021 41.00993, -87.532669 40.74541099999999, -87.53717 40.494609999999994, -87.535675 40.48324600000001, -87.535339 40.16619499999999, -87.535774 39.887302000000005, -87.535576 39.609341, -87.538567 39.47744800000001, -87.540215 39.350525000000005, -87.597664 39.338268, -87.625237 39.30740399999999, -87.610619 39.297661000000005, -87.615799 39.281418, -87.606895 39.258162999999996, -87.584564 39.248752999999994, -87.588593 39.20846599999999, -87.594208 39.198128, -87.607925 39.196068, -87.644257 39.168507000000005, -87.670326 39.146679000000006, -87.659454 39.130652999999995, -87.662262 39.11346800000001, -87.631668 39.10394299999999, -87.630867 39.08897400000001, -87.612007 39.08460600000001, -87.58532 39.062434999999994, -87.581749 38.995743000000004, -87.591858 38.99408299999999, -87.547905 38.97707700000001, -87.53347 38.96370300000001, -87.530182 38.93191899999999, -87.5392 38.90486100000001, -87.559059 38.869811999999996, -87.550507 38.857890999999995, -87.507889 38.795559, -87.519028 38.77669900000001, -87.508003 38.769722, -87.508316 38.73663300000001, -87.543892 38.68597399999999, -87.588478 38.672169, -87.625191 38.642810999999995, -87.628647 38.622917, -87.619827 38.599209, -87.640594 38.593177999999995, -87.652855 38.573871999999994, -87.672943 38.54742400000001, -87.65139 38.51536899999999, -87.653534 38.50044299999999, -87.679909 38.50400500000001, -87.692818 38.48153300000001, -87.756096 38.466125000000005, -87.758659 38.45709600000001, -87.738953 38.44548, -87.748428 38.41796500000001, -87.784019 38.378124000000014, -87.834503 38.35252399999999, -87.850082 38.28609800000001, -87.863007 38.28536199999999, -87.874039 38.316788, -87.883446 38.315552, -87.888466 38.300658999999996, -87.914108 38.281048, -87.913651 38.302345, -87.925919 38.30477099999999, -87.980019 38.241085, -87.986008 38.234814, -87.977928 38.200714000000005, -87.932289 38.171131, -87.931992 38.15752800000001, -87.950569 38.13691299999999, -87.973503 38.131760000000014, -88.018547 38.10330200000001, -88.012329 38.09234599999999, -87.964867 38.09674799999999, -87.975296 38.073307, -88.034729 38.054084999999986, -88.043091 38.04512, -88.041473 38.03830300000001, -88.021698 38.03353100000001, -88.029213 38.00823600000001, -88.021706 37.975055999999995, -88.042511 37.956264000000004, -88.041771 37.934498000000005, -88.064621 37.929783, -88.078941 37.944, -88.084 37.92366, -88.030441 37.917591, -88.026588 37.905758000000006, -88.044868 37.896004000000005, -88.100082 37.90617, -88.101456 37.895306000000005, -88.075737 37.867808999999994, -88.034241 37.843745999999996, -88.042137 37.827522, -88.089264 37.831249, -88.086029 37.817612, -88.035576 37.805683, -88.072472 37.735400999999996, -88.133636 37.700745, -88.15937 37.660686, -88.157631 37.628479, -88.134171 37.583572000000004, -88.071564 37.51099000000001)))
reprojected
MULTIPOLYGON (((-9804081.657847203 4510573.570048137, -9805898.28061746 4505702.664324028, -9830814.254324773 4501015.72870541, -9836098.59055273 4496313.788384076, -9842853.011976104 4497853.114945388, -9848173.081760604 4495115.335828296, -9853035.294479474 4480565.297336921, -9851933.788118074 4475099.443555139, -9846286.772989111 4467813.297693937, -9843149.455780085 4461000.643837322, -9846261.28082572 4452869.190793547, -9849192.211698815 4449167.506882168, -9850739.663940333 4448614.465657501, -9853697.756769184 4448138.739395508, -9858373.175382502 4449261.124945198, -9864489.847443119 4454317.452023299, -9872744.187685441 4457998.039407824, -9878392.872606762 4458804.050146454, -9879215.857602198 4460329.801924502, -9892216.081695508 4467327.6217995165, -9899920.948931275 4469593.788107706, -9906674.59111821 4469821.507927165, -9914674.121046105 4465045.034948174, -9920439.134835308 4454748.786355814, -9923725.954120472 4452103.546096644, -9926308.677626366 4448064.2434366895, -9926841.23007032 4442691.175264947, -9924159.988815073 4438889.345599151, -9921890.62967576 4437450.02223913, -9928976.337903734 4437262.995631081, -9930817.562281456 4443146.019612607, -9933892.985853603 4444925.426762354, -9936828.926103784 4451257.716902817, -9939075.353427993 4451832.666853606, -9941196.88028353 4451014.907621134, -9941910.326900024 4447600.12031354, -9936850.188126527 4442973.115106779, -9936600.498508675 4440317.572799773, -9938912.270373981 4438996.253853614, -9942053.03848722 4440456.419127982, -9950064.47960063 4445968.66655027, -9949734.973907884 4452926.693143724, -9954611.658160556 4458248.410033331, -9956473.254005091 4462175.103896018, -9959556.24730261 4470412.84755195, -9959232.641542876 4474532.874986916, -9961936.035376789 4474850.351029055, -9964640.097127648 4477704.009021743, -9964640.097127648 4481700.233926405, -9963158.991302645 4485126.637721484, -9959614.80135477 4486522.210341316, -9955940.812880628 4488805.815899229, -9955032.000557791 4496553.29910406, -9957931.539334483 4502464.737311692, -9962513.449575534 4507870.489861796, -9965874.185002582 4519132.920866387, -9964582.43363142 4525310.639469115, -9965229.5338314 4530152.582520835, -9964583.212867854 4534296.147807098, -9965490.355398327 4536400.271533974, -9972159.840050224 4537990.954535544, -9981624.445796452 4543529.003925382, -9982670.849009909 4548952.808520223, -9984362.571311494 4551886.335211437, -9988525.029711235 4556987.603436236, -10002247.16070234 4566023.207236599, -10003285.882870933 4566082.885946576, -10003927.973693829 4564162.757935383, -10007683.55935472 4561910.0120879505, -10011838.336709598 4562211.816709335, -10016406.665972773 4566985.444813793, -10014104.244944697 4574289.789724424, -10019957.646409588 4575092.381538184, -10023421.129726637 4578466.092983348, -10032038.928106397 4583985.767760285, -10033750.242638364 4587050.085703865, -10041855.971360477 4591992.731710566, -10047035.88990607 4596698.599642423, -10050996.192110531 4603018.336881153, -10056237.225056568 4606119.038391172, -10059360.070731793 4612577.482428579, -10059869.691360647 4625235.222881119, -10058683.136908278 4631164.0181526365, -10056559.049704453 4634787.332401642, -10052355.069134645 4639974.179227037, -10048341.22225511 4652960.393995351, -10047834.161974547 4654963.872520132, -10045575.934784316 4659239.223492842, -10039204.45240927 4665998.995947451, -10039189.98087547 4672910.786842571, -10041267.425212653 4678841.574563614, -10040636.355019346 4682208.703332439, -10036943.66487075 4689221.727105073, -10033802.117521076 4690990.411295875, -10032304.759050416 4693136.49220776, -10031346.743512647 4697416.436610844, -10033538.735605858 4700641.335474557, -10045908.000825351 4709433.108080555, -10049804.62828108 4710893.658542942, -10054347.46538086 4710920.988635183, -10064737.02477609 4716277.1038072845, -10071056.632268423 4715826.00020265, -10077800.923618136 4706157.36294659, -10082242.793939767 4703256.850119881, -10088575.20317354 4704610.834539867, -10093213.218437953 4712401.359326277, -10097353.524259027 4727086.398941798, -10097522.507246053 4730008.501326762, -10095609.036518807 4735102.1946359705, -10098540.857947828 4742349.662911801, -10098703.050445916 4749767.661822176, -10100277.664643187 4753915.973012006, -10100917.195117794 4757230.647161204, -10105510.237307921 4764275.667575246, -10113430.730397357 4771995.861950482, -10124272.914842147 4779215.456295107, -10134118.901163831 4785531.183069953, -10137240.85628313 4789794.92689745, -10140494.613679526 4797721.521708938, -10147460.542135404 4801137.734314944, -10152699.014733156 4807987.527154785, -10165435.96823074 4820405.016274203, -10170937.711424215 4826008.027807813, -10171642.697759409 4831311.3798096515, -10172565.870296558 4837467.800663898, -10180077.041618345 4846060.845475296, -10180277.528021263 4849279.946300798, -10178392.109805696 4851686.5757499095, -10177984.346510923 4854590.337890092, -10179860.525208753 4858107.5397222275, -10184318.42553706 4866778.325006238, -10186179.24214516 4875641.281075712, -10187528.879651537 4885513.152508497, -10186462.104971264 4895115.337766316, -10185614.518368363 4902539.22352504, -10184252.190440034 4911038.536129932, -10180010.80652132 4920134.15867877, -10176696.04604397 4922322.199239335, -10173015.934997836 4923124.003387151, -10171568.781617524 4924677.374188916, -10172976.082620133 4931149.882711003, -10171795.53942027 4939404.117010152, -10172609.173578478 4943041.728874968, -10176034.362990694 4945897.617376829, -10175839.108603844 4949557.568905235, -10171886.376124755 4954023.8038917845, -10159246.270584162 4959319.137172085, -10153997.556593258 4959946.0080705555, -10148162.85680282 4961779.025136117, -10144451.464979773 4965571.010330402, -10143430.553929705 4968985.156726282, -10140398.656278463 4977233.268681194, -10139970.52151687 4987847.5769731235, -10135551.694329832 4994596.670245673, -10128211.955023868 5001127.380787999, -10125699.808075137 5005043.754075937, -10125025.43459991 5022725.588938968, -10125374.53252304 5027746.799941758, -10128998.427226322 5033659.731877658, -10132106.022131307 5036831.667628284, -10136343.175909372 5038374.543425472, -10141375.26217119 5046551.317376963, -10141466.989431605 5051925.377064774, -10138231.154473227 5061864.950815576, -10136283.731301289 5071726.462726873, -10133133.723670311 5075011.124111179, -10130150.917914506 5076135.905438489, -10124469.171104416 5074673.537160142, -10112723.295033365 5078146.170256631, -10105572.242264293 5078918.283989316, -10097592.193247288 5078954.076874659, -10092090.450053813 5080774.491244318, -10085623.78951414 5087798.550118103, -10078960.204795254 5090234.421034555, -10069403.871788617 5090468.763399351, -10067174.476346498 5092853.10512966, -10065842.76127814 5096377.68358779, -10057534.09712431 5099290.939867389, -10056530.217956336 5101664.96595854, -10056728.923247404 5108558.906123816, -10055047.33101948 5119536.701835704, -10052693.925664619 5124568.752455289, -10047175.150589053 5128340.719408752, -10040554.869152086 5131983.797647508, -10035955.036473017 5150615.508548303, -10034636.123146096 5158577.481854369, -10035511.76226068 5165988.112312521, -10037466.755157989 5170127.779800905, -10037305.45321583 5176532.632466528, -10038355.975250445 5179047.18533362, -10040080.091523852 5179375.265187534, -10044461.626681477 5184934.983299134, -10054777.269934816 5190582.853801676, -10059689.57642454 5192519.928347542, -10064080.46241939 5197396.072847533, -10065283.937434357 5200596.333346887, -10066363.40253658 5212141.977634381, -10067912.52457046 5215070.172096852, -10073416.828112222 5219396.338955011, -10081491.943974365 5224379.5326696215, -10086194.52454344 5230220.722893911, -10090927.717972476 5232496.903027368, -10091309.098547934 5235373.283363911, -10089812.630633201 5237587.2815526575, -10065505.574540526 5237436.423890345, -10010245.9113938 5236794.059994191, -10000343.931368249 5236696.214322979, -9952017.802705582 5235794.813484654, -9947447.803650044 5235857.621875817, -9900652.98590273 5234794.465000342, -9881269.479568353 5234800.8055413775, -9874764.636443337 5234611.949822939, -9829276.932156917 5234961.434001078, -9817789.317304507 5234605.60940872, -9773551.842219185 5234532.996873226, -9777963.990236778 5208163.855569051, -9769425.117375987 5184444.682182559, -9759440.649607757 5169944.7059558295, -9752992.802062029 5138137.880605197, -9743779.555726014 5119664.223398593, -9744089.580507874 5081873.352668125, -9744067.5392487 5056886.0325055, -9743987.723173797 5038004.514775069, -9744020.005826129 5013806.446930743, -9744092.140856162 4974862.059157537, -9744593.189884223 4938080.139428916, -9744426.767245486 4936416.783240098, -9744389.36389658 4890122.75670336, -9744437.787875075 4849578.802714823, -9744415.7466159 4809334.120216452, -9744748.703212861 4790294.49116782, -9744932.15773369 4772006.370827116, -9751327.351160271 4770242.041055282, -9754396.763479913 4765800.702555224, -9752769.495163498 4764399.088851934, -9753346.130125808 4762062.828273016, -9752354.941379784 4758718.961630332, -9749869.06583088 4757366.200756999, -9750317.572059287 4751576.6812662175, -9750942.631000089 4750091.575003462, -9752469.6004553 4749795.671642305, -9756514.060194802 4745837.577368545, -9759416.048000293 4742703.912082091, -9758205.782496387 4740403.810552741, -9758518.367626535 4737937.947208509, -9755112.659125205 4736571.4708002, -9755023.49221308 4734424.359806931, -9752924.00661672 4733797.9121429, -9749953.223365918 4730618.800568355, -9749555.701464297 4721061.812199303, -9750681.030196726 4720824.048536127, -9745788.20461789 4718388.581212782, -9744181.307768287 4716473.671570964, -9743815.289282558 4711924.239963079, -9744819.168450532 4708052.874953907, -9747029.862218197 4703040.378050157, -9746077.857932933 4701336.07176051, -9741333.643874306 4692429.318140128, -9742573.631682253 4689735.907590863, -9741346.334296254 4688739.697550353, -9741381.177296873 4684016.415077351, -9745341.479501337 4676789.343939147, -9750304.770317845 4674820.794170547, -9754391.642783338 4670635.696913094, -9754776.362943519 4667800.7042107945, -9753794.525034722 4664423.224628617, -9756106.296900025 4663564.21674506, -9757471.185176644 4660814.908092914, -9759707.3711077 4657049.728047072, -9757308.10212263 4652488.182239468, -9757546.77111089 4650364.849992316, -9760482.822680563 4650871.530463769, -9761919.845987216 4647675.396447819, -9768963.92072563 4645484.53257022, -9769249.232580533 4644200.916361872, -9767055.570694963 4642549.753153745, -9768110.322870228 4638639.677096441, -9772072.294867052 4632980.627598, -9777692.14804026 4629346.02637084, -9779426.394387327 4619921.075634839, -9780865.198805831 4619816.695535485, -9782093.275428262 4624274.498274765, -9783140.457878156 4624099.134215803, -9783699.281721937 4621986.345767715, -9786553.736104857 4619204.901940741, -9786502.863097565 4622225.50759058, -9787868.530610617 4622569.649362098, -9793890.915062534 4613539.242131068, -9794557.607492894 4612650.468707529, -9793658.146007285 4607818.900338107, -9788577.63576697 4603629.170491141, -9788544.573878204 4601703.199176652, -9790612.556058673 4598785.123374764, -9793165.557260524 4598055.83938258, -9798179.832403816 4594029.216580492, -9797487.647810064 4592479.431662503, -9792204.202138033 4593102.090232319, -9793365.153107516 4589786.815560131, -9799981.204403833 4587069.029371835, -9800912.057985848 4585801.717882557, -9800731.943049742 4584838.1561048785, -9798530.600119308 4584163.7020940315, -9799367.166092617 4580589.348788441, -9798531.490675233 4575902.661285274, -9800847.492681189 4573249.223937362, -9800765.116258 4570176.705064864, -9803308.766622625 4569511.248999743, -9804902.861730786 4571517.908685193, -9805466.02703471 4568647.137191132, -9799503.866427312 4567790.717160487, -9799074.952429285 4566121.120004894, -9801109.872720987 4564745.0647345185, -9807256.267085645 4566179.247330112, -9807409.220065996 4564646.60068051, -9804546.194082284 4560768.451946129, -9799926.880492326 4557375.818290291, -9800805.85919163 4555089.027160649, -9806052.012834245 4555614.307528577, -9805691.894281527 4553692.448811149, -9800075.492012536 4552011.589174394, -9804182.735944845 4542113.987418192, -9810991.481279723 4537236.946740006, -9813856.177055798 4531602.397200321, -9813662.592461308 4527074.485299873, -9811051.037207298 4520764.381898589, -9804081.657847203 4510573.570048137)))
  • Sorry I didn't answer earlier. I had so many things to do .. Nevertheless, thanks for your answer! Strange that my version has a function collection(). But still my problem persists. I have also read your post here previous to making my own question: gis.stackexchange.com/questions/255930/… The answer is somehow the same for both questions. But: in the comments you say that we need to iterate over the features in order for them to exist. Did I understand that correctly? – Leo.1906 Feb 9 at 9:45
  • I want to transform the whole SimpleFeatureCollection to an CRS which works with meters to do a buffer in meters. The buffering takes place in a different class and I want to pass the reprojected SimpleFeatureCollection to that method. Still this wont work because the result is a buffer made in degrees instead of meters. Can't I just pass the ReprojectingFeatureCollection and assume that this is a new SimpleFeatureCollection in my desired CRS? – Leo.1906 Feb 9 at 9:48
  • are you using a recent version of GeoTools (19.x, 20.x)? – Ian Turton Feb 9 at 9:51
  • You can think of FeatureCollections as being like streams (in general) so that the features are only read in when required. – Ian Turton Feb 9 at 9:54
  • I am at GeoTools 20.0. Ok streams makes sense. So I should be able to pass them to another function which iterates trhrough the features and buffers them? Or do I need to iterate through the ReprojectingFeatureCollection myself and create a new Collection before passing this on? – Leo.1906 Feb 9 at 10:36
0

The answer was very simple in the end. When I used this function I just took the first include my IDE was suggesing me to be correct. I was making use of org.geoserver.feature.ReprojectingFeatureCollection;

But somehow the code in this include is not working properly (at least not for me using GeoTools 20.0 - includes automatically loaded by maven). When using the Function as described in my question it was just changing the EPSG Code of the data but did not transform the data itself. That's why further manipulation achieved false outputs (buffering for example still took place in degrees instead of meter).

I did not imediately noticed because when I importet test data into QGis, QGis transformed the data on the fly to the CRS it said it would be. When I finally made a GeoJSON out of it to look at the geometry values itself I realised that something was not right.

Long talk short solution. I changed the import to org.geotools.data.store.ReprojectingFeatureCollection; and that fixed the problem. Now it works like it should.

Don't know if it was my stupidity or if there is a bug in this include for real though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.