Search Results for: qgis org

How to Find MapServer Data and Load Into QGIS

Most Interactive Maps you will find on the Internet are powered by ArcGIS MapServer that can be easily loaded into QGIS once you know the URL for the MapServer. To find the URL, you will need to do a bit of snooping, but the best way to do that is to go to Web Developer Tools in your browser, then to the Network Tab, and keep that open while loading the page. Search for MapServer in the files being loaded. Right click on the MapServer URL and click Copy Value.

With some luck you will find the MapServer URL which looks like this that you can paste into your browser.

https://gis.broomecountyny.gov/arcgis/rest/services/parcels/br_parcels/MapServer

For example, the Broome County Parcel Viewer: https://gis.broomecountyny.gov/website/apps/parcel_mapper/viewer.html

If you enter that URL into your browser in most cases you will be brought to the web interface of the MapServer. It is often helpful to remove anything beyond rest/services to get the full listing of public REST/Services. For Broome County: https://gis.broomecountyny.gov/arcgis/rest/services/

You can enter that URL in the ArcGIS Rest Server tab in the QGIS Data Service Manager.

So I could see all the layers, I only entered the part up through rest/services: https://gis.broomecountyny.gov/arcgis/rest/services/

Then you can load into QGIS and style as you like.

You can also save the layer to your hard drive locally as a Geopackage or Shapefile. This might take some time depending on the size of the MapServer. Parcels are often hundreds of megabytes to download, and REST/Services tend to be slow for large data requests that require many page requests of the server.

You don’t necessarily have to save the file locally, you can query and style the data like any shapefile or geopackage.

This will work for any ArcGIS REST/SERVICE you find on the Internet which is the majority of interactive maps. This list is often helpful to finding a REST/Service quickly: https://mappingsupport.com/p/surf_gis/list-federal-state-county-city-GIS-servers.pdf

Changelog for QGIS 3.18

Changelog for QGIS 3.18

QGIS 3.18 introduces a host of enhancements and new features, along with a long-awaited feature - Native Point Cloud support in QGIS! Thanks to the efforts of Lutra, North Road, and Hobu, QGIS is now able to import and render point cloud data in various formats by leveraging the Open Source PDAL library. This functionality has been introduced due to the success of a crowd-funding campaign and would not have been possible without the support of the QGIS community and contributors. Thank you to all those involved in realizing this incredible milestone!

As QGIS Desktop 3.18 bids farewell to the DB2 database provider, it introduces support for users of the SAP HANA database system.

Changelog for QGIS 3.16

Changelog for QGIS 3.16

QGIS is an amazing place piece of software, and after 18 years of very active development with extensive help from both many volunteers and European governments becomes more and more powerful. 

QGIS Python API – How to Export a Map

Here is the Python code I use with QGIS 3.0 to export to an image from a layout you have previously set up and saved in your project.

        layout = QgsProject.instance().layoutManager().layoutByName("YourLayoutName")
        export = QgsLayoutExporter(layout)
        export.exportToImage("YourPath/YourFilename"+".jpg", QgsLayoutExporter.ImageExportSettings())

For a PDF export you would use:

        layout = QgsProject.instance().layoutManager().layoutByName("YourLayoutName")
        export = QgsLayoutExporter(layout)
        export.exportToPdf("YourPath/YourFilename"+".pdf", QgsLayoutExporter.PdfExportSettings())

The API is a bit confusing, and some things are broken out of the box in QGIS 3.0 but it’s gotten better with subsequent revisions. QGISLayoutExporter API Documentation. I suggest updating your version of QGIS to the latest stable version, which as of now is QGIS 3.4.3 but may be newer depending on when you find this webpage.

Warmth

Code Scrap for Exporting a Map to a Raster PDF

I don’t like the vector Adobe Acrobat PDF that Quantum GIS exports by default if you don’t specifically check “Export as Raster” in the Composer View. It’s true that Vector PDF is a higher quality, but the files are much larger and slower loading. A 300 DPI raster PDF file will suffice for most printing needs.

I struggled for a number of days to figure out the best way to export a Raster PDF from Quantum GIS with PyQGIS. I ended up giving up, preferring to just export a high-resolution JPEG and convert the JPEG to a Adobe PDF using ImageMagick’s convert command. It gave me much smaller PDF files due to higher compression then what you get through the PDF export built into QGIS’s Composers with the “Export as Raster” checked.

When you use printPageAsRaster(0), all settings related to resolution are preserved in the exported file (such as 300 DPI format and 8×10 page size), so ImageMagick automatically converts it over.

You don’t have to include all the libraries that are listed below, I was lazy, and I needed all of them for my map automation plugin, so I left them in. You should remove the ones you don’t use. Don’t forget to change the composer name from Horizontal to the composer you use, and adjust the output paths accordingly.

It may not be elegant, but it works well. This is my solution, it may not be yours.

from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication,QFileInfo,QSizeF
from PyQt4.QtGui import QAction, QIcon, QPrinter,QPainter
from os import sys 

composerId = 0
composers = iface.activeComposers()
for item in composers:
	if item.composerWindow().windowTitle() == 'Horizontal':
		break
	composerId += 1

c = composers[composerId].composition()

image = c.printPageAsRaster(0)
image.save("/tmp/"+QgsProject.instance().title()+".jpg", "jpg")
os.system('convert "/tmp/'+QgsProject.instance().title()+'.jpg" "/tmp/'+QgsProject.instance().title()+'.pdf"')

Evening Down in the Ravine

A follow up to yesterday's post about Vector export of QGIS Composers using PyQGIS. This does the export as a Raster PDF, for much smaller files but with the same or better quality.