[Geotools-gt2-users] Issues with the display of a map
Hello all, I have a JMapFrame with a MapContent containing a raster JPG, a shapefile and 2 feature layers containing points and lines. The frame has a checkbox that change the visibility of the shapefile layer. When the shapefile layer is not visible, I would like the map to be resized in order for the other layers to appear bigger (the shapefile extent, Nz map, is a lot bigger than the other layers). What I have in return is that, when the biggest layer is not visible the others are visualized very small, while when it is visible, the raster is at his biggest dimension and NZ map is cut out of the screen. Below a piece of the code I am using to achieve the goal. I can post the whole frame code and the files (jpg and shp) if necessary. Any help is more than appreciated. Thank you Andrea frame.enableToolBar(true); frame.enableStatusBar(true); JToolBar toolBar = frame.getToolBar(); JCheckBox jcb = new JCheckBox("Shape Visible", true); toolBar.addSeparator(); toolBar.add(jcb); jcb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { shpLayer.setVisible(jcb.isSelected()); recalculateBounds(); } }); private void recalculateBounds() { MapContent content = frame.getMapContent(); MapViewport viewport = content.getViewport(); actualBounds = viewport.getBounds(); maxBounds = null; ReferencedEnvelope maxBounds = null; CoordinateReferenceSystem mapCRS = viewport.getCoordinateReferenceSystem(); for (Layer layer : content.layers()) { if(layer.isVisible()) { ReferencedEnvelope dataBounds = layer.getBounds(); CoordinateReferenceSystem dataCrs = dataBounds.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(dataCrs, mapCRS)){ try { dataBounds = dataBounds.transform(mapCRS, true); catch (TransformException e) { e.printStackTrace(); catch (FactoryException e) { e.printStackTrace(); } if (maxBounds == null) { maxBounds = dataBounds; }else { maxBounds.expandToInclude(dataBounds); } } } viewport.setBounds( maxBounds); } ___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Re: [Geotools-gt2-users] Add attributes (fields) to a shapefile
Hi all, I’ve found a solution to the problem. In the attached file the code. It works for me. Andrea From: Andrea Mari <andrea.m...@niwa.co.nz> Date: Tuesday, 20 March 2018 at 2:24 PM To: geotools-gt2-users <geotools-gt2-users@lists.sourceforge.net> Subject: Add attributes (fields) to a shapefile Hello all, I’ve got 2 shapefiles (Point geometry both) with the same set of features (buildings). The SimpleFeatureType of the 2 shapefiles is different, with the only common columns being the ID (and the lon and lat). They’re both CRS 2193. What I’m trying to do is to create a new shapefile with the attributes of both. adding also the collection of all the features, but it does nothing. After this command (newAttrTypes.addAll(sft2.getTypes());) I can see in the Types both set of values, But when I write them in the new shapefile I get an empty .shp The second file is generated by the first, so, theoretically, number of features and position should be the same. In the Geometry file, there are the Types for each shapefile. In the other file the code I’m using. Any help is really appreciated. Thank you Andrea joinShapeFiles.docx Description: joinShapeFiles.docx -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
[Geotools-gt2-users] Add attributes (fields) to a shapefile
Hello all, I’ve got 2 shapefiles (Point geometry both) with the same set of features (buildings). The SimpleFeatureType of the 2 shapefiles is different, with the only common columns being the ID (and the lon and lat). They’re both CRS 2193. What I’m trying to do is to create a new shapefile with the attributes of both. adding also the collection of all the features, but it does nothing. After this command (newAttrTypes.addAll(sft2.getTypes());) I can see in the Types both set of values, But when I write them in the new shapefile I get an empty .shp The second file is generated by the first, so, theoretically, number of features and position should be the same. In the Geometry file, there are the Types for each shapefile. In the other file the code I’m using. Any help is really appreciated. Thank you Andrea GeometryDescriptorImpl the.docx Description: GeometryDescriptorImpl the.docx public static void joinExample.docx Description: public static void joinExample.docx -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Re: [Geotools-gt2-users] GetMapRequest
Hi all, Thank you very much for your help. Unfortunately, all the options we tried didn’t work. Does the server need to be configured in order to allow wrapping or is something we can do on the client side as well? How can I check if the server allows wrapping or not? Have you got an example on how to do it on the client side in case the server is not set to allow wrapping? Thank you very much in advance for your help Andrea From: <andrea.a...@gmail.com> on behalf of Andrea Aime <andrea.a...@geo-solutions.it> Date: Friday, 23 February 2018 at 11:22 PM To: Ian Turton <ijtur...@gmail.com> Cc: Andrea Mari <andrea.m...@niwa.co.nz>, "geotools-gt2-users@lists.sourceforge.net" <geotools-gt2-users@lists.sourceforge.net> Subject: Re: [Geotools-gt2-users] GetMapRequest On Fri, Feb 23, 2018 at 11:13 AM, Ian Turton <ijtur...@gmail.com<mailto:ijtur...@gmail.com>> wrote: I think the easiest answer is to request two separate images on either side of 180/-180. Some of the data stores handle crossing the antimeridian or possibly that is all handled in GeoServer (see http://blog.geoserver.org/2010/02/23/geoserver-map-wrapping/). So you might get the correct answer by using a WMSLayer rather than making a direct WMS request yourself, but I haven't tried that. GeoServer enables that support in streaming renderer, something like this: Map<Object, Object> rendererParams = new HashMap(); rendererParams.put(StreamingRenderer.ADVANCED_PROJECTION_HANDLING_KEY, true); rendererParams.put(StreamingRenderer.CONTINUOUS_MAP_WRAPPING, true); renderer.setRendererHints(rendererParams); and then the client code should use lontidues above 180 to request an area crossing the dateline, like a WMS client does... at that point it should work... Hope this helps Cheers Andrea == GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it AVVERTENZE AI SENSI DEL D.Lgs. 196/2003 Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003. The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc. -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Re: [Geotools-gt2-users] GetMapRequest
I send it again because with the attachment was too big. Thank you very much, it works now. Now that I’ve solved my issue, I’ve got a second one. The real coordinates I’m using to create a rectangle in the South pacific are getMapRequest.setBBox("162,-24,-156,17"); but due to the fact that I’m going through the 0 meridian, the Envelope doesn’t recognise correctly the minx and maxX (it swaps them) I’ve also tried to use 162 and 203 (assuming to use a 360 degree scale) Any idea? Thank you Andrea From: Andrea Mari <andrea.m...@niwa.co.nz> Date: Friday, 23 February 2018 at 1:18 PM To: Ian Turton <ijtur...@gmail.com> Cc: "geotools-gt2-users@lists.sourceforge.net" <geotools-gt2-users@lists.sourceforge.net> Subject: Re: [Geotools-gt2-users] GetMapRequest Thank you very much, it works now. Now that I’ve solved my issue, I’ve got a second one. The real coordinates I’m using to create a rectangle in the South pacific are getMapRequest.setBBox("162,-24,-156,17"); but due to the fact that I’m going through the 0 meridian, the Envelope doesn’t recognise correctly the minx and maxX (it swaps them) I’ve also tried to use 162 and 203 (assuming to use a 360 degree scale) Any idea? Attached a picture of the area I would like to get from the server. Thank you Andrea From: Ian Turton <ijtur...@gmail.com> Date: Thursday, 22 February 2018 at 10:31 PM To: Andrea Mari <andrea.m...@niwa.co.nz> Cc: "geotools-gt2-users@lists.sourceforge.net" <geotools-gt2-users@lists.sourceforge.net> Subject: Re: [Geotools-gt2-users] GetMapRequest That URL and bounding box work fine for me, using this code https://gitlab.com/snippets/1700238 If it fetches the whole world it is possible you are not setting the bounds of your map viewport, so you may need to add something like (where content is your MapContent): content.getViewport().setCoordinateReferenceSystem(crs); content.getViewport().setBounds(bbox); Ian On 22 February 2018 at 03:11, Andrea Mari <andrea.m...@niwa.co.nz<mailto:andrea.m...@niwa.co.nz>> wrote: Hello all, I’m trying to get a subset of the WGS84 map from a server but it doesn’t work the way I expect. It just keeps showing the whole world What am I doing wrong? MultithreadedHttpClient httpClient = new MultithreadedHttpClient(); httpClient.setReadTimeout(timeout); httpClient.setConnectTimeout(timeout); WebMapServer wms = new WebMapServer(new URL(serviceUrl), httpClient); WMSCapabilities capabilities = wms.getCapabilities(); List layers = capabilities.getLayerList(); defaultWMSLayer = GeoToolsUtils.getDefaultWMSLayer(layers); wmsLayer = new RSWMSLayer(wms, defaultWMSLayer); GetMapRequest getMapRequest = wms.createGetMapRequest(); getMapRequest.addLayer(defaultWMSLayer); getMapRequest.setBBox("162,-24,175,-13"); getMapRequest.setDimensions(mapPane.getSize()); getMapRequest.setFormat("image/png"); getMapRequest.setSRS("CRS:" + CRS.toSRS(crs)); wmsLayer.setTitle(defaultWMSLayer.getTitle()); map.layers().add(0, wmsLayer); serviceUrl =http://ows.terrestris.de/osm/service?SERVICE=WMS=1.1.1=GetCapabilities ("162,-24,175,-13") these are the coordinates in WGS84 to get a map of most of the Pacific Islands Thank you very much for your help Andrea -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net<mailto:GeoTools-GT2-Users@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users -- Ian Turton -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
[Geotools-gt2-users] GetMapRequest
Hello all, I’m trying to get a subset of the WGS84 map from a server but it doesn’t work the way I expect. It just keeps showing the whole world What am I doing wrong? MultithreadedHttpClient httpClient = new MultithreadedHttpClient(); httpClient.setReadTimeout(timeout); httpClient.setConnectTimeout(timeout); WebMapServer wms = new WebMapServer(new URL(serviceUrl), httpClient); WMSCapabilities capabilities = wms.getCapabilities(); List layers = capabilities.getLayerList(); defaultWMSLayer = GeoToolsUtils.getDefaultWMSLayer(layers); wmsLayer = new RSWMSLayer(wms, defaultWMSLayer); GetMapRequest getMapRequest = wms.createGetMapRequest(); getMapRequest.addLayer(defaultWMSLayer); getMapRequest.setBBox("162,-24,175,-13"); getMapRequest.setDimensions(mapPane.getSize()); getMapRequest.setFormat("image/png"); getMapRequest.setSRS("CRS:" + CRS.toSRS(crs)); wmsLayer.setTitle(defaultWMSLayer.getTitle()); map.layers().add(0, wmsLayer); serviceUrl =http://ows.terrestris.de/osm/service?SERVICE=WMS=1.1.1=GetCapabilities ("162,-24,175,-13") these are the coordinates in WGS84 to get a map of most of the Pacific Islands Thank you very much for your help Andrea -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users