Re: [Geotools-gt2-users] [Geotools-devel] An issue about showing more than one shpfilesusing Swing component
First you create a JMapFrame and a MapContent to put in it JMapFrame frame = new JMapFrame(); private MapContent content = new MapContent(); public MapViewer(String[] args) { frame.setSize(300, 300); frame.enableToolBar(true); frame.enableStatusBar(true); frame.setMapContent(content); } Then for each Shapefile (or other datasource) you create a layer and add it to the MapContent HashMapparams = new HashMap<>(); File f = new File(name); params.put("url", URLs.fileToUrl(f)); DataStore ds = null; try { ds = DataStoreFinder.getDataStore(params); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (ds == null) { System.err.println("couldn't find a store for " + name); return; } String type; try { type = ds.getTypeNames()[0]; FeatureLayer layer = new FeatureLayer(ds.getFeatureSource(type), style); System.out.println("adding layer " + name); content.addLayer(layer); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } I've attached the full example to this message. On 11 April 2018 at 02:42, NBA浪仔 <799052...@qq.com> wrote: > Thanks,I realize showing one map in a JPanel according to the URL( > https://github.com/sf2gis/SwingMap), but I don't konw how to realize > adding two map contents in a mapPane,could you give me a demo about it? > > > -- 原始邮件 -- > *发件人:* "Ian Turton" ; > *发送时间:* 2018年4月11日(星期三) 凌晨1:26 > *收件人:* "NBA浪仔"<799052...@qq.com>;"geotools-users" gt2-us...@lists.sourceforge.net>; > *主题:* Re: [Geotools-devel] An issue about showing more than one > shpfilesusing Swing component > > Instead of creating a new mapPane for each layer you need to create just a > new layer and add that to the existing map content object. > > Ian > > On Tue, 10 Apr 2018, 02:11 NBA浪仔, <799052...@qq.com> wrote: > >> Thanks a lot for your replay . Actually, I have realized the goal that >> one panel displays one shp map , >> But I want to display two maps in one JPanel like this ,any suggestions? >> Otherwise,I want to realize zooming in and out in this JPanel,how should >> I do that? >> >> >> >> -- 原始邮件 -- >> *发件人:* "Ian Turton" ; >> *发送时间:* 2018年4月10日(星期二) 凌晨0:34 >> *收件人:* "NBA浪仔"<799052...@qq.com>; >> *抄送:* "geotools-devel" ; >> *主题:* Re: [Geotools-devel] An issue about showing more than one shp >> filesusing Swing component >> >> You need to create a second layer and add that to the map in exactly the >> same way as the first. >> >> Ian >> >> On 9 April 2018 at 11:32, NBA浪仔 <799052...@qq.com> wrote: >> >>> Dear Sir/Madam, >>> With your help earlier,I can display one shp format map file in >>> a JPanel component,like this : >>> >>> >>> Now I want to display two shp format map files in the Swing component >>> --JPanel,how should I do that? >>> >>> Yours sincerely, >>> Ouyang >>> >>> >>> >>> >>> >>> -- >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> ___ >>> GeoTools-Devel mailing list >>> geotools-de...@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/geotools-devel >>> >>> >> >> >> -- >> Ian Turton >> > -- Ian Turton package com.ianturton.geotools; import java.awt.Color; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import javax.xml.parsers.ParserConfigurationException; import org.geotools.data.DataStore; import org.geotools.data.DataStoreFinder; import org.geotools.map.FeatureLayer; import org.geotools.map.MapContent; import org.geotools.styling.SLD; import org.geotools.styling.Style; import org.geotools.styling.StyledLayerDescriptor; import org.geotools.swing.JMapFrame; import org.geotools.util.URLs; import org.xml.sax.SAXException; public class MapViewer { JMapFrame frame = new JMapFrame(); private MapContent content = new MapContent(); public MapViewer(String[] args) { frame.setSize(300, 300); frame.enableToolBar(true); frame.enableStatusBar(true); frame.setMapContent(content); for (String name : args) { add(name); } } public void add(String name) { try { Style style = getStyle(name); add(name,style); } catch (IOException | SAXException | ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void add(String name, Style style) { HashMap params = new HashMap<>(); File f = new File(name); params.put("url", URLs.fileToUrl(f));
Re: [Geotools-gt2-users] Geotools Error on SBT Assembly
Thank you for the succint replies! SBT assembly does exclude files inside the META-INF directory (https://github.com/sbt/sbt-assembly/issues/11). I know what to do now, thanks again! Ken Abryl Eleazar Salanio kssala...@gmail.com On Sun, Apr 15, 2018 at 9:37 PM, Andrea Aimewrote: > Yep, > as Ben said. > See also this FAQ entry, does not talk about SBT, but what the Maven shade > plugin does in this description, you'll have to replicate with SBT: > > http://docs.geotools.org/latest/userguide/build/faq. > html#how-do-i-create-an-executable-jar-for-my-geotools-app > > Cheers > Andrea > > On Sun, Apr 15, 2018 at 2:32 PM, Ben Caradoc-Davies > wrote: > >> Ken, >> >> does your fat jar include all the module META-INF/services SPI files from >> the module jars? (And concatenate those with the same name?) GeoTools loads >> many SPI providers, including those for functions and data stores. If some >> of these entries are omitted from the fat jar, those SPI providers will not >> be found. In particular, the gt-main copy of >> META-INF/services/org.opengis.filter.expression.Function >> will be needed in the fat jar for org.geotools.filter.LengthFunction to >> be available via SPI and found by the filter factory. As can be seen from >> the stack trace below, this function is used to set length restrictions >> when reading shapefiles. >> >> Kind regards, >> Ben. >> >> On 15/04/18 15:58, Ken wrote: >> >>> Hi, I'm trying to use the following: >>> >>> - gt-shapefile v19.0 >>> - SBT 1.0.3 >>> - SBT Assembly v0.14.5 >>> - Scala v2.11.12 >>> >>> If I compile and run via SBT, everything works fine. However if I >>> assemble >>> a fat jar, this error pops out: >>> >>> >>> >>> *Exception in thread "main" java.lang.RuntimeException: Unable to find >>> >>> function Lengthat >>> org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:205) >>> at >>> org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:152) >>> at >>> org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:127) >>> at >>> org.geotools.filter.FilterFactoryImpl.function(FilterFactory >>> Impl.java:754) >>> at >>> org.geotools.feature.AttributeTypeBuilder.lengthRestriction( >>> AttributeTypeBuilder.java:615) >>> at >>> org.geotools.feature.AttributeTypeBuilder.buildType(Attribut >>> eTypeBuilder.java:446) >>> at >>> org.geotools.feature.AttributeTypeBuilder.buildDescriptor(At >>> tributeTypeBuilder.java:507) >>> at >>> org.geotools.data.shapefile.ShapefileFeatureSource.readAttri >>> butes(ShapefileFeatureSource.java:567) >>> at >>> org.geotools.data.shapefile.ShapefileFeatureSource.buildFeat >>> ureType(ShapefileFeatureSource.java:475) >>> at >>> org.geotools.data.shapefile.ShapefileFeatureStore.buildFeatu >>> reType(ShapefileFeatureStore.java:134) >>> at >>> org.geotools.data.store.ContentFeatureSource.getAbsoluteSche >>> ma(ContentFeatureSource.java:356) >>> at >>> org.geotools.data.store.ContentFeatureSource.getSchema(Conte >>> ntFeatureSource.java:325) >>> at >>> org.geotools.data.store.ContentFeatureCollection.(Cont >>> entFeatureCollection.java:80) >>> at >>> org.geotools.data.store.ContentFeatureSource.getFeatures(Con >>> tentFeatureSource.java:583) >>> at >>> thesis.ShapeFileReader$.readSimpleFeatures(ShapeFileReader.scala:41) >>> at >>> thesis.ShapeFileReader$.readMultiPolygonFeatures(ShapeFileRe >>> ader.scala:94) >>> at thesis.Refactored$.maskRaster(Refactored.scala:122)at >>> thesis.Main$$anonfun$run$1$$anonfun$apply$1$$anonfun$2.apply >>> (Main.scala:191) >>> at >>> thesis.Main$$anonfun$run$1$$anonfun$apply$1$$anonfun$2.apply >>> (Main.scala:191) >>> at thesis.Refactored$.time(Refactored.scala:48)at >>> thesis.Main$$anonfun$run$1$$anonfun$apply$1.apply$mcVI$sp(Ma >>> in.scala:190) >>> at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala: >>> 160) >>> at thesis.Main$$anonfun$run$1.apply(Main.scala:181)at >>> thesis.Main$$anonfun$run$1.apply(Main.scala:172)at >>> scala.collection.immutable.List.foreach(List.scala:381)at >>> thesis.Main$.run(Main.scala:172)at >>> thesis.Main$.main(Main.scala:125)at thesis.Main.main(Main.scala) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce >>> ssorImpl.java:62) >>> at >>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe >>> thodAccessorImpl.java:43) >>> at java.lang.reflect.Method.invoke(Method.java:498)at >>> org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy >>> $SparkSubmit$$runMain(SparkSubmit.scala:755) >>> at >>> org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180) >>> at >>>