Recorder mit QGIS verbinden: Unterschied zwischen den Versionen

Aus Recorder-Wiki
Wechseln zu: Navigation, Suche
Zeile 25: Zeile 25:
 
   GO
 
   GO
 
    
 
    
    
+
   DECLARE @SQL as varchar(4000)
   CREATE VIEW [dbo].[bfn_sample_spatial_ref]
+
   DECLARE @SQL2 as varchar(4000)
  AS
+
   SET @SQL ='select s.SAMPLE_KEY,
   select sample_key,
+
    case  
  case  
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 8 then lat + 0.00625  
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 8 then lat + 0.00625 --'qqq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 7 then lat + 0.0125
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 7 then lat + 0.0125 --'qq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 6 then lat + 0.025
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 6 then lat + 0.025 --'q'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 4 then lat + 0.05
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 4 then lat + 0.05 --'m'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 8 then lat + 0.00833333333333333
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 8 then lat + 0.00833333333333333 --'qyx'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 6 then lat + 0.025
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 6 then lat + 0.025 --'q'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 4 then lat + 0.05
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 4 then lat + 0.05 --'m'
+
      else lat
    else lat
+
    end
  end
+
    as lat_center,
  as lat_center,
+
    case
  case
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 8 then long + 0.01041666666666666
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 8 then long + 0.01041666666666666 --'qqq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 7 then long + 0.02083333333333333
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 7 then long + 0.02083333333333333 --'qq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 6 then long + 0.02083333333333333
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 6 then long + 0.02083333333333333 --'q'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 4 then long + 0.08333333333333333
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 4 then long + 0.08333333333333333 --'m'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 8 then long + 0.00833333333333333  
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 8 then long + 0.00833333333333333 --'qyx'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 6 then long + 0.02083333333333333  
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 6 then long + 0.02083333333333333 --'q'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 4 then long + 0.08333333333333333
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 4 then long + 0.08333333333333333 --'m'
+
      else LONG
    else LONG
+
    end
  end
+
    as long_center,
  as long_center,
+
    case
  case
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 8 then geography::Point(lat + 0.00625, long + 0.01041666666666666, 4326) --''qqq''
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 8 then geography::Point(lat + 0.00625, long + 0.01041666666666666, 4326) --'qqq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 7 then geography::Point(lat + 0.0125,  long + 0.02083333333333333, 4326)  --''qq''
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 7 then geography::Point(lat + 0.0125,  long + 0.02083333333333333, 4326)  --'qq'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --''q''
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --'q'
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --''m''
    when Spatial_ref_system = 'QQQ' and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --'m'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 8 then geography::Point(lat + 0.00833333333333333, long + 0.00833333333333333, 4326)  --''qyx''
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 8 then geography::Point(lat + 0.00833333333333333, long + 0.00833333333333333, 4326)  --'qyx'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --''q''
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --'q'
+
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --''m''
    when Spatial_ref_system = 'QYX' and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --'m'
+
      else geography::Point(lat, long, 4326)
    else geography::Point(lat, long, 4326)
+
    end
  end
+
    as center_geom,
  as center_geom
+
    case
   from SAMPLE  
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 8 and data is null then 1300 --''qqq''
  where LAT is not null
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 7 and data is null then 2600  --''qq''
    
+
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 6 and data is null then 5200   --''q''
 +
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 4 and data is null then 10400  --''m''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 8 and data is null then 1000  --''qyx''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 6 and data is null then 5200  --''q''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 4 and data is null then 10400  --''m''
 +
      else dbo.ufn_BfNNumbersFromString(data)
 +
    end
 +
    as usr,
 +
    case
 +
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 8 then ''qqq''
 +
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 7 then ''qq''
 +
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 6 then ''q''
 +
      when Spatial_ref_system = ''QQQ'' and len(spatial_ref) = 4 then  ''m''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 8 then ''qyx''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 6 then ''q''
 +
      when Spatial_ref_system = ''QYX'' and len(spatial_ref) = 4 then ''m''
 +
      else ''p''
 +
    end
 +
    as rtyp
 +
    from SAMPLE s
 +
    left join
 +
    (select MAX(data) as data, SAMPLE_KEY from SAMPLE_DATA
 +
    where MEASUREMENT_UNIT_KEY = ''BFNSYS0000000032''
 +
    and MEASUREMENT_QUALIFIER_KEY = ''BFNSYS0000000099''
 +
    group by SAMPLE_KEY) sd
 +
    on s.SAMPLE_KEY = sd.SAMPLE_KEY
 +
    where LAT is not null
 +
   '
 +
     
 +
  if cast( left(cast(SERVERPROPERTY('productversion') as varchar),CHARINDEX('.',cast(SERVERPROPERTY('productversion') as varchar))-1)as integer) > 9
 +
  EXEC('CREATE VIEW [dbo].[bfn_sample_spatial_ref] AS ' + @SQL)
 
   GO
 
   GO
 
    
 
    
 +
  IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[bfn_sample_spatial_ref]') AND type in (N'V'))
 
   GRANT SELECT ON [dbo].[bfn_sample_spatial_ref] TO PUBLIC
 
   GRANT SELECT ON [dbo].[bfn_sample_spatial_ref] TO PUBLIC
  

Version vom 22. Januar 2014, 18:49 Uhr

Dieses Tutorial ist zur Zeit in Bearbeitung

QGis oder Quantum Gis ist ein benutzerfreundliches, frei verfügbares und quelloffenes Geoinformationssystem zum Betrachten, Bearbeiten und Erfassen von räumlichen Daten. Seit Erscheinen der Version Dufor 2.0 ist es besonders gut geeignet, Beobachtungsdaten der Recorder-Datenbank in einem GIS-System darzustellen.

Vorausetzung dafür ist, dass die Recorder-Datenbank auf dem Microsoft SQL Server 2008 oder 2012 eingebunden ist. Dieser kann Geometrie-Daten nutzen und verwalten.

Vorbereitende Arbeiten

1. Schritt: QGIS installieren

Installieren Sie QGIS von der offiziellen Website des Projektes.

2. Schritt: Recorder Datenbank für QGIS optimieren

Um die Recorder-Datenbank effektiv unter QGIS einbinden zu könnenUnter Recorder müssen sei mindestens ein zusätzliches View erstellen. Öffnen Sie dazu das SQL Server Management Studio und verbinden Sie sich mit der Datenbank-Instanz, auf der Ihre Recorder Datenbank liegt.

Wählen Sie die Recorder-Datenbank im Objekt-Explorer aus. Starten Sie eine neue Abfrage mit Datei→Neu→Abfrage mit aktueller Verbindung (Strg+N). Kopieren Sie den folgenden Quellcode in das Abfragefenster:

 IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[bfn_sample_spatial_ref]') AND type in (N'V'))
 DROP VIEW [dbo].[bfn_sample_spatial_ref]
 
 GO
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 
 DECLARE @SQL as varchar(4000)
 DECLARE @SQL2 as varchar(4000)
 SET @SQL ='select s.SAMPLE_KEY,
   case 
     when Spatial_ref_system = QQQ and len(spatial_ref) = 8 then lat + 0.00625 
     when Spatial_ref_system = QQQ and len(spatial_ref) = 7 then lat + 0.0125
     when Spatial_ref_system = QQQ and len(spatial_ref) = 6 then lat + 0.025
     when Spatial_ref_system = QQQ and len(spatial_ref) = 4 then lat + 0.05
     when Spatial_ref_system = QYX and len(spatial_ref) = 8 then lat + 0.00833333333333333
     when Spatial_ref_system = QYX and len(spatial_ref) = 6 then lat + 0.025
     when Spatial_ref_system = QYX and len(spatial_ref) = 4 then lat + 0.05
     else lat
   end
   as lat_center,
   case
     when Spatial_ref_system = QQQ and len(spatial_ref) = 8 then long + 0.01041666666666666
     when Spatial_ref_system = QQQ and len(spatial_ref) = 7 then long + 0.02083333333333333
     when Spatial_ref_system = QQQ and len(spatial_ref) = 6 then long + 0.02083333333333333
     when Spatial_ref_system = QQQ and len(spatial_ref) = 4 then long + 0.08333333333333333
     when Spatial_ref_system = QYX and len(spatial_ref) = 8 then long + 0.00833333333333333 
     when Spatial_ref_system = QYX and len(spatial_ref) = 6 then long + 0.02083333333333333 
     when Spatial_ref_system = QYX and len(spatial_ref) = 4 then long + 0.08333333333333333
     else LONG
   end
   as long_center,
   case
     when Spatial_ref_system = QQQ and len(spatial_ref) = 8 then geography::Point(lat + 0.00625, long + 0.01041666666666666, 4326) --qqq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 7 then geography::Point(lat + 0.0125,  long + 0.02083333333333333, 4326)  --qq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --q
     when Spatial_ref_system = QQQ and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --m
     when Spatial_ref_system = QYX and len(spatial_ref) = 8 then geography::Point(lat + 0.00833333333333333, long + 0.00833333333333333, 4326)  --qyx
     when Spatial_ref_system = QYX and len(spatial_ref) = 6 then geography::Point(lat + 0.025, long + 0.02083333333333333, 4326)  --q
     when Spatial_ref_system = QYX and len(spatial_ref) = 4 then geography::Point(lat + 0.05, long + 0.08333333333333333, 4326)  --m
     else geography::Point(lat, long, 4326)
   end
   as center_geom,
   case
     when Spatial_ref_system = QQQ and len(spatial_ref) = 8 and data is null then 1300 --qqq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 7 and data is null then 2600   --qq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 6 and data is null then 5200   --q
     when Spatial_ref_system = QQQ and len(spatial_ref) = 4 and data is null then 10400   --m
     when Spatial_ref_system = QYX and len(spatial_ref) = 8 and data is null then 1000   --qyx
     when Spatial_ref_system = QYX and len(spatial_ref) = 6 and data is null then 5200   --q
     when Spatial_ref_system = QYX and len(spatial_ref) = 4 and data is null then 10400   --m
     else dbo.ufn_BfNNumbersFromString(data)
   end
   as usr,
   case
     when Spatial_ref_system = QQQ and len(spatial_ref) = 8 then qqq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 7 then qq
     when Spatial_ref_system = QQQ and len(spatial_ref) = 6 then q
     when Spatial_ref_system = QQQ and len(spatial_ref) = 4 then  m
     when Spatial_ref_system = QYX and len(spatial_ref) = 8 then qyx
     when Spatial_ref_system = QYX and len(spatial_ref) = 6 then q
     when Spatial_ref_system = QYX and len(spatial_ref) = 4 then m
     else p
   end
   as rtyp
   from SAMPLE s
   left join 
   (select MAX(data) as data, SAMPLE_KEY from SAMPLE_DATA 
    where MEASUREMENT_UNIT_KEY = BFNSYS0000000032 
    and MEASUREMENT_QUALIFIER_KEY = BFNSYS0000000099
    group by SAMPLE_KEY) sd
   on s.SAMPLE_KEY = sd.SAMPLE_KEY
   where LAT is not null
 '
     
 if cast( left(cast(SERVERPROPERTY('productversion') as varchar),CHARINDEX('.',cast(SERVERPROPERTY('productversion') as varchar))-1)as integer) > 9 
 EXEC('CREATE VIEW [dbo].[bfn_sample_spatial_ref] AS ' + @SQL)
 GO
 
 IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[bfn_sample_spatial_ref]') AND type in (N'V'))
 GRANT SELECT ON [dbo].[bfn_sample_spatial_ref] TO PUBLIC


Führen Sie das Script aus. Drücken Sie dazu den Ausführen-Knopf auf der SQL-Editor-Symbolleite, oder wählen Sie Abfrage→Ausführen.

Der Code erstellt ein neues View in Ihrer Recorder Datenbank. Dabei werden aus den Recorder Raumreferenzen der Aufnahmen (Tabelle Sample) Geometrien erzeugt und gleichzeitig Koordinaten von Rasterpunkten der deutschen Rastersysteme in das Zentrum des Rasters verlegt.

Schritt 3: DNS erstellen

Um Quantum GIS mit dem SQL-Server verbinden zu können, müssen Sie zunächst eine DNS erstellen.

Windows 7

Klicken Sie im Menü Start auf Systemsteuerung, in der Systemsteuerung auf Verwaltung und dort auf Datenquellen (ODBC); alternativ geben Sie im Startmenü "Datenquellen ein und wählen den gefundenen Eintrag "Datenquellen (ODBC)" aus.

Wählen Sie den Reiter "Benutzer-DSN". Klicken Sie auf [Hinzufügen] Wählen Sie den Treiber "SQL Server" aus der Treiberliste aus (es sind auch andere möglich, gegebenenfalls müssen Sie das austesten. Vergeben Sie einen Namen für die DSN (z.B. Recorder und geben Sie unter Server die SQL-Server Instanz Ihrer Recorder-Datenbank an. Diese setzt sich aus em Computernamen + dem Instanznamen susammen also MeinPC/Instanz. Im Zweifelsfall nutzen Sie das kleine Tool RecorderInfo. Sie finden es unter Ihrer Recorder Installation im Ordner Helferlein. Starten Sie das Programm mit Doppelklick, wählen Sie Recorder 6 Infos holen. Suchen Sie den Eintrag unter Server Name: und kopieren Sie den Inhalt.

Bestätigen Sie mit Fertigstellen. Die neu erstellte Datenbankverbindung kann jetzt genutzt werden.


Schritt 4: Verbindung zu Recorder in QGIS erstellen.

Wählen Sie aus dem Hauptmenü Layer→Räumlichen MSSQL Layer hinzufügen. Klicken Sie auf Neu und erstellen Sie eine neue Verbindung mit folgenden Daten:

Name: Recorder (frei wählbar!)
Lieferant/DSN: RecorderTestdb (Name der soeben erstellten DSN)
Host: (kein Eintrag!)
Datenbank: NBNData (abweichenden Datenbanknamen mit RecorderInfo erfragen)
Vertrauenswürdige Verbindung: ausgewählt



 IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[v_qgis_link]') AND type in (N'V'))
 DROP VIEW [dbo].[v_cts_qgis_link]
 
 GO
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 
 
 CREATE VIEW [dbo].[v_cts_qgis_link]
 as
 select bssr.center_geom, itn.ACTUAL_NAME, s.SAMPLE_REFERENCE, itn.SORT_ORDER, ldf.datestring
 from bfn_sample_spatial_ref bssr
 inner join SAMPLE s
 on bssr.sample_key = s.SAMPLE_KEY 
 join taxon_occurrence toc on toc.SAMPLE_KEY = s.SAMPLE_KEY
 join LC_DATE_FILTER ldf on ldf.TAXON_OCCURRENCE_KEY = toc.TAXON_OCCURRENCE_KEY
 left join TAXON_DETERMINATION td on td.TAXON_OCCURRENCE_KEY = toc.TAXON_OCCURRENCE_KEY
 join INDEX_TAXON_NAME itn on itn.TAXON_LIST_ITEM_KEY = td.TAXON_LIST_ITEM_KEY
 where td.PREFERRED = 1
 
 GO
 
 GRANT SELECT ON [dbo].[v_cts_qgis_link] TO PUBLIC