diff --git a/autotest/ogr/data/gml/min_example/ft1_schema.xsd b/autotest/ogr/data/gml/min_example/ft1_schema.xsd new file mode 100644 index 000000000000..a1d71b57ff07 --- /dev/null +++ b/autotest/ogr/data/gml/min_example/ft1_schema.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/autotest/ogr/data/gml/min_example/ft2_schema.xsd b/autotest/ogr/data/gml/min_example/ft2_schema.xsd new file mode 100644 index 000000000000..08439de44bc9 --- /dev/null +++ b/autotest/ogr/data/gml/min_example/ft2_schema.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/autotest/ogr/data/gml/min_example/minimal_example.gml b/autotest/ogr/data/gml/min_example/minimal_example.gml new file mode 100644 index 000000000000..31282fae09e7 --- /dev/null +++ b/autotest/ogr/data/gml/min_example/minimal_example.gml @@ -0,0 +1,55 @@ + + + + + + Rechtsbestand + 430050 + 2021-01-13+01:00 + + + + + + + + 431972.151 5347601.362 431964.001 5347621.025 431963.856 5347621.360 431956.503 5347639.346 431955.348 5347642.027 431946.479 5347638.798 431947.704 5347635.782 431940.320 5347632.646 431940.752 5347631.530 431947.244 5347615.889 431947.460 5347615.331 431952.550 5347600.374 431933.614 5347599.266 431911.933 5347598.080 431892.851 5347597.085 431878.817 5347596.364 431869.832 5347595.804 431854.833 5347594.983 431838.573 5347594.178 431818.376 5347593.085 431792.611 5347591.726 431758.084 5347589.805 431735.436 5347588.520 431731.173 5347591.906 431728.161 5347606.839 431723.676 5347628.792 431721.715 5347650.938 431733.163 5347652.690 431746.073 5347652.536 431783.096 5347652.203 431811.603 5347653.307 431823.703 5347653.718 431835.730 5347654.240 431866.763 5347655.648 431875.746 5347655.985 431885.769 5347656.421 431893.342 5347656.775 431897.351 5347656.950 431914.654 5347658.077 431924.753 5347658.734 431929.434 5347659.234 431929.953 5347659.228 431947.776 5347660.460 431964.722 5347662.703 431979.637 5347668.972 431992.836 5347674.484 432002.386 5347678.817 432009.223 5347679.625 432013.965 5347679.123 432026.152 5347674.309 432033.238 5347671.223 432049.740 5347642.567 432046.810 5347639.601 432047.754 5347637.811 432058.913 5347615.334 432066.808 5347599.121 432072.679 5347587.378 432074.245 5347588.138 432091.528 5347556.472 432072.344 5347546.918 432050.620 5347535.949 432045.918 5347533.671 432038.566 5347551.879 432032.299 5347567.628 432027.252 5347580.028 432025.523 5347584.384 432022.856 5347590.974 432020.624 5347596.670 432013.056 5347615.437 432000.188 5347619.036 431986.354 5347610.086 431972.967 5347601.353 431972.151 5347601.362 + + + + + + + + + + + 430070 + 2004-02-26+01:00 + 8266.565325510000000 + + + + + + + + 510586.451 5282926.087 510579.955 5282909.071 510578.087 5282904.956 510574.792 5282901.504 510570.005 5282892.827 510563.498 5282882.145 510556.314 5282871.907 510548.528 5282862.557 510546.805 5282860.887 510539.391 5282853.427 510537.215 5282852.868 510536.092 5282851.866 510535.345 5282849.863 510529.578 5282844.630 510523.285 5282839.283 510520.438 5282836.833 510510.099 5282829.034 510494.586 5282819.115 510475.245 5282809.633 510450.727 5282800.476 510442.555 5282796.904 510440.289 5282805.125 510437.725 5282812.455 510433.622 5282841.344 510431.571 5282855.567 510428.379 5282877.789 510427.163 5282886.678 510424.276 5282906.789 510456.971 5282916.295 510465.753 5282914.533 510464.393 5282919.643 510460.259 5282923.636 510455.585 5282935.854 510453.023 5282942.406 510447.304 5282951.287 510443.543 5282957.060 510469.192 5282962.663 510493.040 5282968.485 510507.141 5282970.845 510519.369 5282971.533 510539.995 5282974.905 510566.854 5282975.621 510580.431 5282977.090 510591.818 5282986.558 510594.415 5282961.223 510591.371 5282943.546 510588.986 5282934.983 510586.451 5282926.087 + + + + + + + + + 510782.868 5283252.645 510784.376 5283248.425 510788.725 5283250.100 510792.850 5283250.330 510838.847 5283246.304 510855.506 5283244.667 510879.146 5283240.489 510903.164 5283234.754 510950.903 5283222.063 510977.629 5283213.222 510986.789 5283209.461 510995.585 5283199.808 511013.361 5283202.064 511025.750 5283196.420 511043.924 5283187.230 511069.535 5283172.830 511086.886 5283162.305 511106.717 5283149.117 511110.471 5283147.790 511123.993 5283138.369 511140.221 5283126.731 511175.681 5283101.681 511193.260 5283090.156 511213.766 5283077.637 511233.067 5283067.227 511243.733 5283061.469 511267.011 5283050.733 511293.591 5283040.115 511311.985 5283033.816 511334.736 5283024.524 511367.164 5283016.029 511389.832 5283010.962 511401.538 5283009.984 511409.042 5283009.443 511428.027 5283007.480 511441.309 5283006.395 511457.967 5283005.317 511472.298 5283004.789 511498.634 5283004.507 511519.567 5283003.882 511526.096 5283003.339 511531.873 5283003.018 511539.527 5283002.477 511545.005 5283001.710 511564.744 5282998.304 511588.538 5282993.016 511611.283 5282987.283 511631.630 5282979.988 511645.668 5282976.126 511654.526 5282973.699 511671.572 5282966.175 511686.665 5282959.982 511702.663 5282951.234 511740.462 5282921.858 511763.377 5282942.910 511770.049 5282945.591 511775.076 5282945.712 511779.583 5282943.165 511782.505 5282944.949 511822.034 5282913.243 511824.515 5282911.248 511825.340 5282910.916 511826.241 5282910.807 511827.141 5282910.809 511828.042 5282910.921 511828.866 5282911.257 511829.691 5282911.592 511830.440 5282912.037 511831.114 5282912.595 511831.713 5282913.263 511832.236 5282914.042 511832.610 5282914.821 511834.212 5282938.608 511828.029 5282954.044 511852.613 5282966.320 511851.216 5282952.313 511852.850 5282923.198 511852.126 5282910.637 511851.185 5282893.853 511850.446 5282888.294 511847.448 5282886.733 511861.425 5282875.758 511865.183 5282872.543 511864.139 5282869.762 511863.398 5282864.982 511850.637 5282831.391 511855.517 5282829.845 511919.784 5282809.305 511922.636 5282808.421 511929.815 5282820.439 511934.810 5282836.231 511934.196 5282842.454 511933.661 5282847.454 511937.490 5282846.128 511987.718 5282830.005 512045.183 5282797.226 512047.224 5282790.006 512054.215 5282783.464 512068.803 5282767.934 512109.633 5282725.341 512137.673 5282699.393 512137.224 5282698.947 512127.865 5282689.592 512105.777 5282667.540 512077.698 5282639.586 512027.723 5282605.362 512115.531 5282523.078 512155.990 5282479.707 512176.683 5282451.520 512185.750 5282421.753 512184.438 5282403.302 512183.634 5282392.964 512173.659 5282390.720 512160.526 5282391.804 512152.346 5282392.454 512143.868 5282391.769 512137.797 5282388.756 512130.459 5282381.294 512122.314 5282365.272 512120.825 5282359.379 512117.723 5282335.811 512116.232 5282331.362 512114.442 5282326.024 512106.658 5282316.338 512088.172 5282293.294 512071.333 5282272.254 512071.943 5282267.253 512069.087 5282269.470 512066.231 5282271.687 512028.429 5282300.394 512012.880 5282308.253 512016.771 5282313.485 512014.291 5282315.147 511973.113 5282343.735 511888.879 5282402.022 511886.400 5282403.796 511894.263 5282411.369 511899.730 5282416.716 511894.169 5282420.372 511841.500 5282454.829 511796.419 5282484.522 511753.969 5282512.444 511746.470 5282510.206 511741.071 5282508.639 511686.251 5282494.081 511694.314 5282477.092 511696.197 5282473.428 511702.750 5282460.772 511711.105 5282447.896 511738.487 5282413.498 511743.978 5282406.619 511744.429 5282406.175 511765.490 5282381.211 511763.017 5282379.316 511749.906 5282369.732 511743.162 5282364.828 511736.719 5282360.147 511726.604 5282352.791 511722.708 5282349.894 511718.588 5282346.551 511708.999 5282338.641 511697.313 5282328.948 511688.698 5282321.818 511656.825 5282350.984 511646.115 5282340.737 511641.172 5282336.060 511637.428 5282332.496 511628.815 5282324.254 511626.793 5282322.361 511630.480 5282317.033 511655.817 5282292.189 511659.952 5282288.085 511665.065 5282283.094 511678.295 5282270.895 511681.228 5282267.789 511685.440 5282263.240 511693.862 5282254.478 511695.518 5282251.480 511697.702 5282247.594 511700.564 5282242.488 511700.278 5282235.485 511695.934 5282231.031 511675.107 5282214.429 511668.141 5282208.858 511656.378 5282199.499 511655.323 5282201.609 511646.583 5282219.818 511643.517 5282214.477 511638.433 5282205.131 511633.424 5282196.230 511628.486 5282188.662 511625.492 5282184.989 511604.915 5282155.718 511597.130 5282146.255 511594.059 5282143.581 511581.052 5282156.115 511570.147 5282168.652 511524.346 5282220.463 511514.122 5282230.335 511513.373 5282229.333 511510.441 5282232.106 511503.825 5282238.428 511499.089 5282242.975 511494.428 5282247.411 511498.100 5282250.086 511494.341 5282253.746 511497.716 5282254.530 511511.635 5282273.674 511512.682 5282275.010 511529.371 5282297.827 511457.163 5282347.475 511455.510 5282348.583 511450.344 5282342.794 511436.456 5282345.989 511434.353 5282346.986 511426.468 5282350.527 511340.249 5282390.813 511328.608 5282396.236 511329.596 5282389.903 511328.714 5282380.343 511327.464 5282367.115 511325.848 5282349.218 511324.598 5282336.323 511323.929 5282332.877 511319.990 5282313.086 511319.693 5282311.863 511312.526 5282293.066 511301.745 5282280.375 511296.954 5282274.809 511291.341 5282267.352 511283.706 5282257.334 511284.764 5282253.780 511294.018 5282240.906 511292.978 5282236.125 511290.492 5282240.565 511278.454 5282257.435 511275.218 5282261.986 511255.063 5282285.397 511236.636 5282307.812 511231.087 5282306.357 511227.336 5282305.682 511224.845 5282313.235 511215.962 5282328.111 511230.423 5282338.919 511233.118 5282342.592 511221.745 5282364.465 511214.143 5282376.676 511211.578 5282383.562 511210.070 5282387.781 511204.065 5282388.437 511190.330 5282390.411 511183.417 5282395.732 511179.133 5282399.058 511174.925 5282402.385 511165.544 5282403.033 511157.740 5282403.574 511154.738 5282403.791 511152.937 5282403.898 511141.757 5282404.099 511135.678 5282404.310 511131.101 5282404.412 511128.925 5282404.075 511118.424 5282402.610 511104.396 5282400.693 511101.470 5282400.354 511089.243 5282398.664 511086.467 5282398.325 511080.240 5282397.758 511073.414 5282397.078 511069.962 5282396.738 511066.136 5282396.397 511061.260 5282395.833 511059.010 5282395.606 511057.283 5282395.713 511050.680 5282396.146 511039.574 5282396.680 511026.516 5282397.433 511022.014 5282397.647 510986.814 5282401.915 510959.050 5282402.751 510955.674 5282402.412 510952.449 5282401.850 510947.575 5282399.729 510943.831 5282395.944 510938.813 5282391.044 510933.420 5282385.921 510930.130 5282380.136 510929.460 5282377.244 510920.751 5282379.673 510909.190 5282382.875 510897.776 5282387.077 510891.394 5282389.510 510889.817 5282390.174 510885.463 5282391.166 510879.232 5282392.599 510873.527 5282393.922 510866.246 5282395.576 510857.237 5282397.670 510851.007 5282398.992 510848.155 5282399.876 510842.148 5282401.755 510838.846 5282402.193 510827.664 5282403.506 510825.788 5282403.391 510808.981 5282402.693 510808.531 5282402.803 510808.599 5282406.471 510822.832 5282419.278 510813.278 5282432.375 510806.057 5282442.031 510800.565 5282450.023 510797.705 5282454.130 510795.449 5282457.349 510788.895 5282471.229 510784.601 5282480.446 510782.039 5282485.998 510775.109 5282500.656 510768.255 5282515.091 510791.113 5282529.471 510783.962 5282541.905 510754.432 5282524.291 510747.204 5282537.502 510732.063 5282529.139 510717.442 5282523.444 510673.654 5282506.248 510673.721 5282510.805 510667.942 5282511.128 510657.965 5282510.331 510657.652 5282517.333 510656.514 5282523.776 510654.250 5282530.886 510649.727 5282542.547 510640.757 5282565.203 510639.400 5282568.646 510634.576 5282580.751 510630.204 5282591.635 510627.112 5282599.965 510624.396 5282608.184 510622.963 5282612.294 510621.838 5282612.181 510618.064 5282624.288 510619.414 5282624.847 510617.825 5282631.846 510549.934 5282624.942 510551.844 5282606.163 510576.300 5282608.319 510576.532 5282604.763 510577.838 5282588.094 510591.567 5282589.009 510591.644 5282588.008 510592.639 5282577.118 510593.712 5282564.672 510609.767 5282566.035 510609.996 5282563.702 510612.669 5282538.256 510612.669 5282538.144 510597.515 5282536.561 510600.794 5282507.670 510590.137 5282509.096 510590.167 5282492.425 510590.197 5282476.087 510601.657 5282446.212 510580.052 5282443.616 510556.298 5282425.901 510547.009 5282417.549 510542.584 5282457.551 510515.900 5282441.944 510515.099 5282428.939 510511.743 5282417.708 510504.448 5282426.919 510497.602 5282436.576 510491.507 5282446.567 510485.935 5282457.005 510476.974 5282474.771 510470.575 5282486.651 510499.962 5282501.041 510503.560 5282502.826 510497.984 5282515.819 510495.268 5282523.928 510493.686 5282528.037 510489.685 5282541.367 510490.422 5282548.704 510487.948 5282547.365 510459.313 5282531.754 510444.847 5282523.948 510440.034 5282529.719 510433.042 5282537.042 510430.337 5282539.593 510426.729 5282543.254 510420.340 5282549.133 510413.351 5282555.345 510412.523 5282557.010 510411.017 5282560.230 510402.977 5282566.662 510388.926 5282577.862 510387.347 5282579.082 510386.897 5282579.414 510385.695 5282580.190 510370.218 5282591.387 510335.734 5282616.333 510332.128 5282618.882 510319.058 5282627.528 510316.428 5282629.302 510299.526 5282640.497 510293.967 5282644.155 510296.886 5282648.495 510280.951 5282664.471 510277.943 5282668.578 510273.424 5282677.794 510269.344 5282694.236 510267.148 5282705.234 510263.907 5282713.898 510263.604 5282715.120 510263.377 5282716.453 510263.225 5282717.675 510263.223 5282719.009 510263.370 5282720.232 510263.593 5282721.455 510263.891 5282722.678 510264.339 5282723.790 510264.938 5282724.903 510265.611 5282725.904 510266.360 5282726.906 510267.259 5282727.796 510268.158 5282728.576 510269.207 5282729.244 510275.655 5282732.034 510277.680 5282731.927 510294.480 5282736.180 510319.077 5282743.225 510330.178 5282745.135 510371.947 5282758.213 510421.891 5282772.528 510433.069 5282773.215 510437.278 5282769.110 510440.728 5282769.894 510443.879 5282769.677 510451.594 5282777.027 510456.388 5282781.481 510483.684 5282789.643 510497.626 5282797.004 510515.091 5282806.705 510521.912 5282810.162 510538.993 5282824.753 510547.382 5282832.658 510555.095 5282840.452 510564.231 5282849.916 510571.941 5282860.044 510578.827 5282869.392 510584.066 5282876.181 510583.381 5282881.403 510587.953 5282884.524 510600.925 5282888.771 510609.173 5282891.453 510610.264 5282910.460 510611.214 5282924.021 510612.964 5282951.810 510614.818 5282963.593 510616.679 5282971.710 510620.785 5282982.610 510624.294 5282992.174 510626.304 5283001.180 510625.627 5283001.734 510627.923 5283018.521 510628.366 5283021.967 510629.193 5283021.302 510629.255 5283028.526 510627.892 5283035.303 510625.548 5283045.079 510617.176 5283069.293 510614.676 5283082.291 510614.442 5283087.626 510615.542 5283101.187 510619.121 5283113.641 510620.026 5283110.753 510623.725 5283098.534 510628.700 5283085.873 510636.833 5283069.106 510646.017 5283052.452 510647.071 5283050.564 510659.938 5283029.582 510661.744 5283026.918 510662.271 5283026.030 510668.439 5283017.039 510673.630 5283009.380 510682.200 5283000.393 510689.191 5282993.071 510690.319 5282991.739 510696.330 5282986.749 510700.162 5282983.644 510703.392 5282981.428 510707.750 5282978.435 510711.130 5282976.107 510716.237 5282973.449 510725.249 5282968.686 510734.261 5282963.924 510736.814 5282962.595 510741.398 5282958.936 510754.471 5282948.624 510759.055 5282944.965 510762.211 5282942.526 510767.771 5282937.868 510775.286 5282931.547 510783.101 5282925.004 510792.043 5282917.464 510794.824 5282915.135 510809.395 5282906.604 510815.554 5282903.059 510818.933 5282901.398 510827.269 5282897.190 510834.028 5282893.869 510842.663 5282890.106 510848.519 5282887.672 510859.858 5282882.802 510876.897 5282878.611 510893.833 5282889.313 510902.658 5282904.889 510912.067 5282928.579 510898.536 5282942.558 510894.101 5282947.106 510893.273 5282947.882 510890.793 5282950.545 510879.968 5282961.750 510874.105 5282967.741 510873.653 5282968.296 510872.826 5282969.183 510868.317 5282973.398 510861.327 5282979.942 510858.170 5282982.826 510849.603 5282990.923 510848.250 5282992.143 510843.289 5282996.802 510840.659 5282999.242 510836.074 5283003.568 510829.385 5283009.779 510827.957 5283011.110 510821.644 5283016.989 510813.452 5283024.643 510810.821 5283027.083 510807.514 5283030.188 510805.711 5283031.852 510797.519 5283039.395 510791.356 5283045.051 510783.691 5283052.150 510775.950 5283059.249 510772.267 5283062.687 510765.803 5283068.566 510759.190 5283074.666 510758.364 5283075.331 510752.127 5283080.210 510735.147 5283093.182 510725.005 5283101.055 510719.671 5283104.601 510725.506 5283113.614 510732.326 5283117.850 510742.733 5283129.650 510751.118 5283139.001 510753.214 5283141.450 510760.327 5283149.466 510770.434 5283161.043 510774.701 5283165.941 510775.366 5283171.388 510776.169 5283183.615 510778.286 5283215.294 510782.197 5283250.421 510782.868 5283252.645 + + + + + + + + + diff --git a/autotest/ogr/data/gml/min_example/minimal_example.xsd b/autotest/ogr/data/gml/min_example/minimal_example.xsd new file mode 100644 index 000000000000..df213dd1a8a4 --- /dev/null +++ b/autotest/ogr/data/gml/min_example/minimal_example.xsd @@ -0,0 +1,5 @@ + + + + + diff --git a/autotest/ogr/ogr_gml.py b/autotest/ogr/ogr_gml.py index fc70d74f1766..d4624b100a7b 100755 --- a/autotest/ogr/ogr_gml.py +++ b/autotest/ogr/ogr_gml.py @@ -4448,3 +4448,181 @@ def test_ogr_gml_ogr2ogr_from_layers_with_inconsistent_srs( gdal.VSIFCloseL(f) assert b"" in data + + +#################################################################################### +# Test if gml can access and use imported schemas along with included schemas +# Open option is set to NO to disable the functionality + + +def test_ogr_gml_USE_SCHEMA_IMPORT_NO(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + ds = gdal.OpenEx( + tmp_path / "minimal_example.gml", open_options=["USE_SCHEMA_IMPORT=NO"] + ) + layer_count = ds.GetLayerCount() + assert ( + layer_count != 2 + ), f"Expected number of layers as '1' without open option set, but got {layer_count} " + + +############################################################################### +# Test if gml can access and use imported schemas along with included schemas +# Open option is set to YES to enable the functionality + + +def test_ogr_gml_USE_SCHEMA_IMPORT_YES(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + ds = gdal.OpenEx( + tmp_path / "minimal_example.gml", open_options=["USE_SCHEMA_IMPORT=YES"] + ) + + layer_count = ds.GetLayerCount() + assert ( + layer_count == 2 + ), f"Expected number of layers as '2' with open option set, but got {layer_count} " + + +############################################################################### +# Test if gml can access and use imported schemas along with included schemas +# Config option is set to YES to enable the functionality + + +def test_ogr_gml_GML_USE_SCHEMA_IMPORT_YES(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + with gdal.config_option("GML_USE_SCHEMA_IMPORT", "YES"): + ds = ogr.Open(tmp_path / "minimal_example.gml") + + layer_count = ds.GetLayerCount() + assert ( + layer_count == 2 + ), f"Expected number of layers as '2' with config option set, but got {layer_count} " + + +############################################################################### +# Test if gml can access and use imported schemas along with included schemas +# Config option is set to NO to disable the functionality + + +def test_ogr_gml_GML_USE_SCHEMA_IMPORT_NO(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + with gdal.config_option("GML_USE_SCHEMA_IMPORT", "NO"): + ds = ogr.Open(tmp_path / "minimal_example.gml") + + layer_count = ds.GetLayerCount() + assert ( + layer_count == 1 + ), f"Expected number of layers as '1' without config option set, but got {layer_count} " + + +######################################################################################################## +# Test if gml can access and use imported schemas along with included schemas with some features testing +# Open option is set to TRUE to enable the functionality + + +def test_ogr_gml_get_layers_by_name_from_imported_schema(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + ds = gdal.OpenEx( + tmp_path / "minimal_example.gml", open_options=["USE_SCHEMA_IMPORT=YES"] + ) + layer_count = ds.GetLayerCount() + assert layer_count == 2, f"Expected number of layers as '2', but got {layer_count} " + + # layer sanier + lyr = ds.GetLayerByName("sanier") + feat = lyr.GetNextFeature() + assert lyr is not None, "cannot find sanier" + + arokstatus = feat.GetFieldAsString("arokstatus") + assert ( + arokstatus == "Rechtsbestand" + ), f"Expected 'arokstatus' to be 'Rechtsbestand', but got {arokstatus}" + + # layer entwick + lyr = ds.GetLayerByName("entwick") + feat = lyr.GetNextFeature() + assert lyr is not None, "cannot find entwick" + + shape_len = feat.GetFieldAsDouble("SHAPE_Leng") + assert ( + shape_len == 8266.565325510000000 + ), f"Expected 'shape_len' to be '8266.565325510000000', but got {shape_len}" + + +####################################################################################################### +# Test if gml can access and use imported schemas along with included schemas with some features testing +# Open option is set to TRUE to enable the functionality + + +def test_ogr_gml_get_layers_by_name_from_imported_schema_more_tests(tmp_path): + + # copy schema files and gml + shutil.copy("data/gml/min_example/ft1_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/ft2_schema.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.xsd", tmp_path) + shutil.copy("data/gml/min_example/minimal_example.gml", tmp_path) + + ds = gdal.OpenEx( + tmp_path / "minimal_example.gml", open_options=["USE_SCHEMA_IMPORT=YES"] + ) + + layer_count = ds.GetLayerCount() + assert layer_count == 2, f"Expected number of layers as '2', but got {layer_count} " + + # layer entwick + lyr = ds.GetLayerByName("entwick") + feat = lyr.GetNextFeature() + shape_len = feat.GetFieldAsDouble("SHAPE_Leng") + assert ( + shape_len == 8266.565325510000000 + ), f"Expected 'shape_len' to be '8266.565325510000000', but got {shape_len}" + + oa_nr = feat.GetFieldAsDouble("oa_nr") + assert isinstance( + oa_nr, float + ), f"Expected 'oa_nr' to be of type 'float', but got {type(oa_nr).__name__}" + assert oa_nr == 430070, f"Expected oa_nr to be '430070', but got {oa_nr}" + + # layer sanier + lyr = ds.GetLayerByName("sanier") + feat = lyr.GetNextFeature() + oa_nr = feat.GetFieldAsString("oa_nr") + assert isinstance( + oa_nr, str + ), f"Expected 'oa_nr' to be of type 'str', but got {type(oa_nr).__name__}" + assert oa_nr == "430050", f"Expected oa_nr to be '430050', but got {oa_nr}" + + dat_erst = feat.GetFieldAsDateTime("dat_erst") + assert isinstance( + dat_erst, list + ), f"Expected 'dat_erst' to be of type 'list', but got {type(dat_erst)}" diff --git a/autotest/ogr/ogr_hana.py b/autotest/ogr/ogr_hana.py index fb17c2898167..f9a9ddc1e2c6 100644 --- a/autotest/ogr/ogr_hana.py +++ b/autotest/ogr/ogr_hana.py @@ -1170,6 +1170,56 @@ def create_feature(fid, geom_wkt=None): layer.CommitTransaction() +############################################################################### +# Test REAL_VECTOR type + + +def test_ogr_hana_38(): + conn = create_connection() + layer_name = get_test_name() + table_name = f'"{gdaltest.hana_schema_name}"."{layer_name}"' + execute_sql( + conn, + f"CREATE COLUMN TABLE {table_name} (ID INT PRIMARY KEY, EMB1 REAL_VECTOR(3), EMB2 REAL_VECTOR)", + ) + execute_sql( + conn, + f"INSERT INTO {table_name} VALUES (1, TO_REAL_VECTOR('[0.1,0.2,0.3]'), TO_REAL_VECTOR('[0.1,0.2,0.3]'))", + ) + + def check_value(expected): + ds = open_datasource(0) + layer = ds.GetLayerByName(layer_name) + layer_defn = layer.GetLayerDefn() + assert layer.GetLayerDefn().GetFieldCount() == 2 + field_emb1 = layer_defn.GetFieldDefn(layer_defn.GetFieldIndex("EMB1")) + assert field_emb1.GetType() == ogr.OFTBinary + assert field_emb1.GetWidth() == 16 + field_emb2 = layer_defn.GetFieldDefn(layer_defn.GetFieldIndex("EMB2")) + assert field_emb2.GetType() == ogr.OFTBinary + assert field_emb2.GetWidth() == 65000 + check_feature_count(layer, 1) + feat = layer.GetNextFeature() + assert feat.GetFieldAsBinary("EMB1") == expected + assert feat.GetFieldAsBinary("EMB2") == expected + + # '[0.1,0.2,0.3]' + vec0 = b"\x03\x00\x00\x00\xCD\xCC\xCC\x3D\xCD\xCC\x4C\x3E\x9A\x99\x99\x3E" + # '[0.1,0.2,0.1]' + vec1 = b"\x03\x00\x00\x00\xCD\xCC\xCC\x3D\xCD\xCC\x4C\x3E\xCD\xCC\xCC\x3D" + + check_value(vec0) + + ds = open_datasource(1) + layer = ds.GetLayerByName(layer_name) + feat = layer.GetNextFeature() + feat.SetField("EMB1", vec1) + feat.SetField("EMB2", vec1) + layer.SetFeature(feat) + + check_value(vec1) + + ############################################################################### # Create a table from data/poly.shp @@ -1248,7 +1298,9 @@ def create_tpoly_table(ds, layer_name="TPOLY"): def get_connection_str(): uri = gdal.GetConfigOption("OGR_HANA_CONNECTION_STRING", None) if uri is not None: - conn_str = uri + ";ENCRYPT=YES;SSL_VALIDATE_CERTIFICATE=false;CHAR_AS_UTF8=1" + if "ENCRYPT" not in uri: + uri += ";ENCRYPT=YES" + conn_str = uri + ";SSL_VALIDATE_CERTIFICATE=false;CHAR_AS_UTF8=1" else: pytest.skip("OGR_HANA_CONNECTION_STRING not set") diff --git a/doc/source/drivers/vector/gml.rst b/doc/source/drivers/vector/gml.rst index a33969974d93..6b05f1213f95 100644 --- a/doc/source/drivers/vector/gml.rst +++ b/doc/source/drivers/vector/gml.rst @@ -115,6 +115,11 @@ The following configuration options are available: Equivalent of :oo:`READ_MODE`. See :ref:`gml_performance`. +- .. config:: GML_USE_SCHEMA_IMPORT + :choices: YES, NO + + Equivalent of :oo:`USE_SCHEMA_IMPORT`. + Parsers ------- @@ -626,6 +631,12 @@ The following open options are supported: Whether to use gml:boundedBy at feature level as feature geometry, if there are no other geometry. +- .. oo:: USE_SCHEMA_IMPORT + :choices: YES, NO + :default: NO + + Whether to use schema imports in XSD files so that + the feature types corresponding to imported schema can be detected. .. note:: diff --git a/frmts/ogcapi/gdalogcapidataset.cpp b/frmts/ogcapi/gdalogcapidataset.cpp index 110ad71ba1e3..2d51f64ce230 100644 --- a/frmts/ogcapi/gdalogcapidataset.cpp +++ b/frmts/ogcapi/gdalogcapidataset.cpp @@ -1655,7 +1655,9 @@ ParseXMLSchema(const std::string &osURL, std::vector apoClasses; bool bFullyUnderstood = false; - bool bHaveSchema = GMLParseXSD(osURL.c_str(), apoClasses, bFullyUnderstood); + bool bUseSchemaImports = false; + bool bHaveSchema = GMLParseXSD(osURL.c_str(), bUseSchemaImports, apoClasses, + bFullyUnderstood); if (bHaveSchema && apoClasses.size() == 1) { auto poGMLFeatureClass = apoClasses[0]; diff --git a/ogr/ogrsf_frmts/gml/ogrgmldatasource.cpp b/ogr/ogrsf_frmts/gml/ogrgmldatasource.cpp index d9463991ef84..063d92ee7c53 100644 --- a/ogr/ogrsf_frmts/gml/ogrgmldatasource.cpp +++ b/ogr/ogrsf_frmts/gml/ogrgmldatasource.cpp @@ -557,6 +557,7 @@ bool OGRGMLDataSource::Open(GDALOpenInfo *poOpenInfo) const char *pszExposeFid = CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "EXPOSE_FID", CPLGetConfigOption("GML_EXPOSE_FID", nullptr)); + if (pszExposeFid) bExposeFid = CPLTestBool(pszExposeFid); @@ -1124,9 +1125,12 @@ bool OGRGMLDataSource::Open(GDALOpenInfo *poOpenInfo) if (bHasFoundXSD) { std::vector aosClasses; + bool bUseSchemaImports = CPLFetchBool( + poOpenInfo->papszOpenOptions, "USE_SCHEMA_IMPORT", + CPLTestBool(CPLGetConfigOption("GML_USE_SCHEMA_IMPORT", "NO"))); bool bFullyUnderstood = false; - bHaveSchema = - GMLParseXSD(osXSDFilename, aosClasses, bFullyUnderstood); + bHaveSchema = GMLParseXSD(osXSDFilename, bUseSchemaImports, + aosClasses, bFullyUnderstood); if (bHaveSchema && !bFullyUnderstood && bIsWFSJointLayer) { diff --git a/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp b/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp index 8a016dbe20cc..a0dab5493cbc 100644 --- a/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp +++ b/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp @@ -216,6 +216,9 @@ void RegisterOGRGML() "